FileSystemInfo为字符串数组

时间:2012-08-31 12:34:53

标签: c# .net windows

我想知道将FileSystemInfo转换为字符串数组的最有效方法是 - 我的代码如下:

    string[] filePaths;
    DirectoryInfo di = new DirectoryInfo(batchDirectory);
    FileSystemInfo[] files = di.GetFileSystemInfos();
    filePaths = files.OrderBy(f => f.CreationTime); 

我试过了:

filePaths = files.OrderBy(f => f.CreationTime).ToArray; 

但没有运气

2 个答案:

答案 0 :(得分:3)

试试这个:

filePaths = files.OrderBy(f => f.CreationTime).Select(x => x.FullName).ToArray(); 

答案 1 :(得分:0)

将括号()添加到Array;

 files.OrderBy(f => f.CreationTime).ToArray();