Reputation: 23820
This is my list
List<KeyValuePair<string, int>> lstRodsMonsterPool = new List<KeyValuePair<string, int>>();
Now i am trying to sort it like this but it is giving error
lstRodsMonsterPool = (from entry in lstRodsMonsterPool
orderby entry.Value ascending
select entry)
.ToList<new KeyValuePair<string,int>(pair => pair.Key, pair => pair.Value)>;
C# 4.0
Thank you
Upvotes: 0
Views: 754
Reputation: 116458
It looks like you're trying to sort the list in place, so you can use the Comparison<T>
overload of List.Sort
:
lstRodsMonsterPool.Sort((l,r) => l.Value.CompareTo(r.Value))
Upvotes: 1
Reputation: 6438
lstRodsMonsterPool = lstRodsMonsterPool.OrderBy(x => x.Value).ToList();
Upvotes: 1