ali yami ali yami - 12 days ago 4
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

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

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