C# Sort files by natural number ordering in the name?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have files in directory like that 0-0.jpeg 0-1.jpeg 0-5.jpeg 0-9.jpeg 0-10.jpeg 0-12.jpeg .... when i loading files: FileInfo[] files = di.GetFiles(); They getting in wrong order (they should go like above): 0-0.jpeg 0-1.jpeg 0-10.jpeg 0-12.jpeg 0-5.jpeg 0-9.jpeg How to fix that? I was trying to sort them but no way: 1) Array.Sort(files, (f1, f2) => f1.Name.CompareTo(f2.Name)); 2) Array.Sort(files, (x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name)); 回答1: Alphabetically, the "wrong" order is in fact correct. If you want it