c# - How to sort a list by a specific property in .NET 2.0? -
this question has answer here:
- how sort list<t> property in object 19 answers
in .net 4.0 can use linq sort list specific property:
list<point> list = ...; sorted = list.orderby(p => p.x).tolist(); // sort list of points x
can similar when cannot use .net 4.0 linq syntax?
is there one-liner sort syntax?
check sort method, takes comparison<t>
. avaliable .net 2.0
var list = new list<point>{ /* populate list */ }; list.sort(comparison); public int comparison (point a, point b) { //do logic comparison , b return -1; }
Comments
Post a Comment