C# - sorting by a property

后端 未结 3 1228
梦谈多话
梦谈多话 2021-01-27 19:22

I am trying to sort a collection of objects in C# by a custom property. (For context, I am working with the Twitter API using the Twitterizer library, sorting Direct Messages in

3条回答
  •  执念已碎
    2021-01-27 20:22

    Have you tried Linq's OrderBy?

    var mySortedList = myCollection.OrderBy(x => x.PropertyName).ToList();
    

    This is still going to loop through the values to sort - there's no way around that. This will at least clean up your code.

提交回复
热议问题