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)

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

Leave a Reply