我一直在尝试深入探索C#的更多高级特性,比如LINQ和Lambda表达式,所以我在LINQ和Lambda表达式方面是一个完整的初学者。
我的问题是,我有我的电脑上包含的文件的路径列表,并希望根据“上次访问时间”对它们进行排序。要做到这一点,我写了下面的以下LINQ查询有什么问题?
TempList = FilesList.OrderByDescending((FileInfo Files,string n) => { Files = new FileInfo(n) ;
Files.LastAccessTime ; } ) ;
FilesList
包含各种顺序文件的路径。 FilesList
类型list<string>
和TempList
的类型是IEnumerable<string>
。
为了这个查询编译器生成以下错误:
The type arguments for method 'System.Linq.Enumerable.OrderByDescending<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
可有人请指出什么是错我的查询。我无法从错误消息中理解。
+1感谢您的回答@Grant Winney –
祝您好运! LINQ很棒。我不知道现在没有它我该如何工作。 –