LINQ, how to add an order to this statement?

I have the following LINQ, which I would also like to order by the date the file was created, how to do this?

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

or

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

Source: https://habr.com/ru/post/1735841/


All Articles