2014-04-15 77 views
0

我希望按照文件名的最後10個字符的順序對文件進行排序,我希望在一條指令中完成。以最近10個字符的順序獲取文件列表

// this works 

string s = "...blabla20140129.u", s2 = s.Substring(s.Length - 10,8); 

// this fails with the message 
var directory = new DirectoryInfo(dir).GetFiles(fileSpec).OrderBy(f => f.FullName.Substring(f.FullName.Length - 10),8); 

Error 1 The type arguments for method 'System.Linq.Enumerable.OrderBy<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TKey>, System.Collections.Generic.IComparer<TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. 

它必須使用.NET 3.5或更小

任何意見理解來解決。

回答

1

您只是有你的括號放錯了地方:

.OrderBy(f => f.FullName.Substring(f.FullName.Length - 10, 8)); 
相關問題