ali yami ali yami - 1 year ago 123
C# Question

Sort Three Dimensional Dictionary by value in c#

I have the following three dimensional Dictionary.

class CopyDir
public class MyFileInfo
public int Num{ get; set; }
public long Size { get; set; }
public static Dictionary<string, MyFileInfo> logInfo;

I want to sort the dictionary based on size Field.

logInfo.OrderBy says
Error CS1061 'Dictionary' does not contain a definition for 'OrderBy' and no extension method 'OrderBy' accepting a first argument of type 'Dictionary' could be found (are you missing a using directive or an assembly reference?)

Answer Source

You can sort it easily using LINQ extensions. We are sorting the values of the dictionary.

var sorted = logInfo.Values.OrderBy(x=>x.Size);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download