且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何排序列表< T>基于T的属性?

更新时间:2022-06-03 09:35:39

使用排序方法和lambda表达式,它是很容易。

Using the sort method and lambda expressions, it is really easy.

myList.Sort((a, b) => String.Compare(a.Name, b.Name))

上面的例子说明如何通过你的对象类型的名称属性进行排序,假设名称为字符串类型。

The above example shows how to sort by the Name property of your object type, assuming Name is of type string.