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
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With