C# 订购1,2,10,11代替1,10,11,2

C# 订购1,2,10,11代替1,10,11,2,c#,.net,C#,.net,我的文件夹中有以下名称的文件: "C:\\Users\\John\\Documents\\333\\12.html" 如何对它们进行排序,使2.html排在10.html之前?看看这篇文章- 排序文件时,将字符串解析为数字 例如: string[] files = { "2.html", "10.html", "1.html" }; files = files.OrderBy(s => Int32.Parse(s.Substring(0, s.IndexOf('.')

我的文件夹中有以下名称的文件:

"C:\\Users\\John\\Documents\\333\\12.html"
如何对它们进行排序,使2.html排在10.html之前?

看看这篇文章-


排序文件时,将字符串解析为数字

例如:

string[] files = {
  "2.html",
  "10.html",
  "1.html"
};

files =
  files.OrderBy(s => Int32.Parse(s.Substring(0, s.IndexOf('.'))))
  .ToArray();

Windows资源管理器?诺顿指挥官
DirectoryInfo.GetFiles()
?单击资源管理器列“Name”以反转排序!这与c有什么关系?@CodeCaster我需要用c做这件事#可能与anmespace是NumericComparer的内容重复?@user1322207看看链接有一个源代码示例要下载,我也编辑了我的答案,然后在“Part 1.html”、“a.html”和“b.html”上失败。您的解决方案仅适用于文件名看起来像
@penartur:符合规范的特定情况。阅读问题。问题是“文件名就像
3.html
”,而不是“文件名就是
”。在问题的上下文中,
part 3.html
类似于
3.html
@penartur:示例显示了它使用的字符串类型。无论任何人怎么想这个问题的意思,答案本身就定义了它所回答的问题。
string[] files = {
  "2.html",
  "10.html",
  "1.html"
};

files =
  files.OrderBy(s => Int32.Parse(s.Substring(0, s.IndexOf('.'))))
  .ToArray();
    Directory
      .GetFiles()
      .OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f)) )