LINQ如何通过此语句添加订单?

时间:2010-03-08 00:23:11

标签: c# linq

我有以下LINQ,我想按文件创建日期排序,这是怎么做的?

taskFiles = taskDirectory.GetFiles(Id + "*.xml")
 .Where(fi => !fi.Name.EndsWith("_update.xml", StringComparison.CurrentCultureIgnoreCase))
 .ToArray();

1 个答案:

答案 0 :(得分:4)

taskFiles = taskDirectory.GetFiles(Id + "*.xml")
 .Where(fi => !fi.Name.EndsWith("_update.xml", StringComparison.CurrentCultureIgnoreCase))
 .OrderBy(fi => fi.CreationTime)
 .ToArray();

var taskFiles = from taskFile in taskDirectory.GetFiles(Id + "*.xml")
                where !taskFile.Name.EndsWith("_update.xml", StringComparison.CurrentCultureIgnoreCase)
                orderby taskFile.CreationTime
                select taskFile;