view raw
ali yami ali yami - 6 months ago 42
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?)


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

var sorted = logInfo.Values.OrderBy(x=>x.Size);