Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda OrderBy method

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
like image 718
Princess Avatar asked Nov 02 '12 19:11

Princess


1 Answers

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()
like image 188
D Stanley Avatar answered Oct 19 '22 10:10

D Stanley