形如,
1) ICollection<ImageInfo> imageInfos = new List<ImageInfoDTO>();
imageInfos = imageInfos.OrderBy(i => i.CreationTime).ToList();
2)IList<string> fileNameList = new List<string>();
fileNameList = fileNameList.OrderBy(i => i).ToList();
此处OrderBy不同于Linq中的OrderBy,需注意。
附,微软官方定义:
class Pet { public string Name { get; set; } public int Age { get; set; } } public static void OrderByEx1() { Pet[] pets = { new Pet { Name="Barley", Age=8 }, new Pet { Name="Boots", Age=4 }, new Pet { Name="Whiskers", Age=1 } }; IEnumerable<Pet> query = pets.OrderBy(pet => pet.Age); foreach (Pet pet in query) { Console.WriteLine("{0} - {1}", pet.Name, pet.Age); } }
参考自:https://msdn.microsoft.com/en-us/library/bb534966(v=vs.110).aspx