arrays - find a value in a nested categorized static class in C# -


i need find value inside structure (the first came in mind static class, do) has hierarchical structure like:

public static class sheetgroups {     public static class coverage {         public static string sheet1 = "covc1";         public static string sheet2 = "covc2";     }      public static class incomeinvestment     {         public static string income1 = "ieic1";         public static string income2 = "ieic2";         public static string income3 = "ieic3";         public static string incomes4 = "ieic4";         public static string investment1 = "ieic5";     } } 

the problem structure need groups (coverage , incomeinvestment) have values (like nested enum), , other problem have implement ifexiststring method find if string exists within values assigned.

i've been searching solution while now, cannot find clean approach this. wondering, need validate correct structure excel file, root (sheetgroups) stands zip file containing number indetermined of excel files, nested clases (coverage , incomeinvestment) excel files, have sheets (covc1, covc2, etc), plan have 1 more level, have columns of tables in every sheet.

thanks

omar

i believe should easier handle if use dictionary inside dictionary inside dictionary [...] aproach:

// i'm using collection initializers here!  var groups = new dictionary<string, dictionary<string, string>> {      {            "coverage",            new dictionary<string, string>            {                { "sheet1", "covc1" },                { "sheet2", "covc2" }                // , on...           }      },      {           "incomeinvestment",           new dictionary<string, string>           {                { "income1", "ieic1" }                // , on...           }      } }; 

now can access values way:

string sheet1 = groups["coverage"]["sheet1"]; 

... or might check if key exists using out-of-the-box idictionary<tkey, tvalue>.containskey(system.string) method!

i believe approach should simplify task , can use standard, out-of-the-box dictionary capabilities search, validate or access values.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -