Wednesday, March 28, 2012

Sorting Dictionary<TKey,TValue> by value or by key using LINQ

Code:
var sortedDict = (from entry in SortedWebsiteNames orderby entry.Value   
ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);  
var sortedDict = (from entry in SortedWebsiteNames orderby entry.Value   
ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
Source: StackOverflow

0 comments:

Post a Comment