How to order a dictionary by Value in C# and VB.NET

To order/sort a dictionary by Value in C# and VB.NET you can use the snippet below.

Sample C#

MyDict = MyDict.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

Sample VB.NET

MyDict = MyDict.OrderBy(Function(x) x.Value).ToDictionary(Function(x) x.Key, Function(x) x.Value)

Please Share us:
Please rate this snippet

2 thoughts on “How to order a dictionary by Value in C# and VB.NET

Leave a Reply