Custom Linq Ordering

前端 未结 5 1491
小蘑菇
小蘑菇 2021-02-09 00:34

I have over a thousand folders, each folder contains one or more files with the following names:

Unordered:

Alison.ext
Heather.ext
Molly.ext
Paula.ext
Sam.ext         


        
5条回答
  •  日久生厌
    2021-02-09 00:49

    You didn't mention exactly what sort of objects you have in the list, but let's say it's some generic arrangement like so:

    public class File {
      public string FileName { ... }
      public long FileSize { ... }
      /* elided */
    }
    

    Then, given an IEnumerable called, say, files, you can just do:

    var result = files.OrderBy(f => f.FileName);
    

提交回复
热议问题