Furkan Gözükara
Furkan Gözükara

Reputation: 23820

Sort C# keyvalue pair list into another keyvalue pair list

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

Answers (3)

lc.
lc.

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

Dmitry Khryukin
Dmitry Khryukin

Reputation: 6438

lstRodsMonsterPool  = lstRodsMonsterPool.OrderBy(x => x.Value).ToList();

Upvotes: 1

SLaks
SLaks

Reputation: 887413

.ToList() doesn't take parameters.

Upvotes: 5

Related Questions