Natural Sort Order in C#

后端 未结 17 2126
野性不改
野性不改 2020-11-21 04:54

Anyone have a good resource or provide a sample of a natural order sort in C# for an FileInfo array? I am implementing the IComparer interface in

17条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 05:30

    Adding to Greg Beech's answer (because I've just been searching for that), if you want to use this from Linq you can use the OrderBy that takes an IComparer. E.g.:

    var items = new List();
    
    // fill items
    
    var sorted = items.OrderBy(item => item.Name, new NaturalStringComparer());
    

提交回复
热议问题