I have sorted dictionary like below:
var map = new SortedDictionary<string, List<Account>>();
I need to sort it by value size (so List>.Count). How do I do that?
I tried as suggested by this forum:
List<KeyValuePair<string, List<Account>>> myList = map.ToList();
myList.Sort(delegate (KeyValuePair<string, List<Account>> pair1,
KeyValuePair<string, List<Account>> pair2)
{
return pair1.Value.Count.CompareTo(pair2.Value.Count);
}
);
but that didn't work
While shown method should work (and it did for me), I would suggest to use the LINQ here: