new { Path = p, Da-6ren">
gpt4 book ai didi

c# 获取 LINQ 语句中的最后一个元素

转载 作者:太空宇宙 更新时间:2023-11-03 17:15:33 26 4
gpt4 key购买 nike

    var filePaths = Directory.GetFiles(@"\\Pontos\completed\", "*_*.csv").Select(p => new { Path = p, Date = System.IO.File.GetLastWriteTime(p) })
.OrderBy(x => x.Date)
.Where(x => x.Date >= LastCreatedDate);

我想知道最近的x.Date

的值

如何从这个 linq 语句中获取最新日期?

请注意,我不需要文件路径,而是需要DATE

最佳答案

var mostRecent = Directory.GetFiles(@"\\Pontos\completed\", "*_*.csv")
.Select(p => new { Path = p, Date = System.IO.File.GetLastWriteTime(p) })
.OrderBy(x => x.Date)
.Where(x => x.Date >= LastCreatedDate)
.LastOrDefault();

var mostRecent = Directory.GetFiles(@"\\Pontos\completed\", "*_*.csv")
.Select(p => new { Path = p, Date = System.IO.File.GetLastWriteTime(p) })
.OrderByDescending(x => x.Date)
.Where(x => x.Date >= LastCreatedDate)
.FirstOrDefault();

关于c# 获取 LINQ 语句中的最后一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com