Lambda OrderBy method
27,176
OrderByDescending
does not reorder the list in-place. It returns an enumerator that you can use to get a new ordered list. You need to use .ToList()
to replace the original list:
nodeList = nodeList.OrderByDescending(Function(x) x.Count).ToList()
Comments
-
Princess almost 2 years
I have a graphing class to detect circular dependencies in some business logic I am writing. My graphing class builds nodes that knows the relationship to other nodes.
I have nodeList as List(of Objects) each having a List(of String)
I was thinking that the below line of code would yield the correct sorting. I thought wrong.
nodeList.OrderByDescending(Function(x) x.Count)
I want to reorder my nodeList in descending order by the List(of String).Count.
my List(of Object) (0) | Count = 3 (1) | Count = 5 (2) | Count = 2 My desired output List(of Object) (0) | Count = 5 (1) | Count = 3 (2) | Count = 2
-
Dylan Meador over 11 yearsThis assumes that each node has a Count property that returns the Count of the contained string list. Something like
x.MyStringList.Count
might be worth mentioning.