我正在加载字符串数组中目录中的文件列表。我在用System.IO.Directory.GetFiles(),
String[] path = Directory.GetFiles(batchElements[j].DocIdPath, "*.csv", SearchOption.AllDirectories);我假设返回值的默认排序顺序是按名称排序的。因此,我的文件按以下顺序加载。
但是相反,我想按这个顺序收集值。
感谢帮助。
发布于 2016-01-18 16:34:19
你可以:
Path.GetFileNameWithoutExtension获取文件名_的拆分int.Parse或int.TryParse解析它OrderBy中与LINQ一起使用该值代码:
var output = path.OrderBy(p =>
int.TryParse(Path.GetFileNameWithoutExtension(p).Split('_').Last(), out temp) ?
temp : int.MaxValue);如果需要一个数组或List<T>作为输出,那么将ToArray()或ToList()附加到查询中。
https://stackoverflow.com/questions/34859475
复制相似问题