How can I sort List based on properties of T?

后端 未结 4 895
误落风尘
误落风尘 2020-12-28 18:21

My Code looks like this :

Collection optionInfoCollection = ....
List optionInfoList = new List

        
4条回答
  •  既然无缘
    2020-12-28 19:10

    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.

提交回复
热议问题