关于泛型数据结构中OrderBy的使用

mac2022-06-30  24

形如,

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

转载于:https://www.cnblogs.com/Jashinck/p/7108179.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)