i have a list like this :
List list_lines = new List();
list_lines.add(\"name1__pass1__com__14__55\");
list_lines.add(\"name2__pas
The other answers create a new list which is sorted the way you want. If instead you want the same list to be sorted, maybe try something like this:
Func getNum = str => int.Parse(str.Split(Separator, StringSplitOptions.None)[4]);
list_lines.Sort((x, y) => getNum(x).CompareTo(getNum(y)));
This uses an overload of List<>.Sort. If you want descending order, swap x
and y
in the Comparison<>
lambda body.
If your list is very long, this is faster (uses Quick Sort) and doesn't require the memory of a new copy of the list.