by
0
5
3,350
1
Top 1% !
Popular
Famous
Tuned
OpenSource
Popularity: 3823rd place

Published on:

No tags for this snippet yet.
.NETFramework4.0
Architecturex86_64
ClassNameCollectionUtils
Extension.cs
InputDefValue2false
InputName0input
InputName1maxResults
InputName2ascend
InputType0Dictionary<string,int>
InputType1int
InputType2bool
LanguageCSharp
LicenseMIT_X11
MethodNameSortDictionaryByValue
OSWindows
OutputTypeList<string>
Windows VersionWindows7

Retrieve the keys of a dictionary sorted by values

Returns the key set ordered by the values.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/215960/Retrieve-the-keys-of-a-dictionary-sorted?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static List<string> SortDictionaryByValue(Dictionary<string, int> input, int maxResults, bool ascend = false) { if (input == null) return new List<string>(); if (ascend) return input.OrderBy((e) => e.Value).Take(maxResults).Select(e => e.Key).ToList(); else return input.OrderByDescending((e) => e.Value).Take(maxResults).Select(e => e.Key).ToList(); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus