I have the following data, i want to define in a elegant way and fast access.
Dictionary<string, string> myDictionary = new Dictionary<string, string>
{
{"a", "1"},
{"b" "2"}
};
Now the "1" and "2" defined in 2 different modules x and y. I'm thinking of nested dictionary here. I'm looking for elegant way to define.
My thinking:
//FileA - Namespace1
Dictionary<string, string> dcA = new Dictionary<string, string>
{
{"LOC1", "ADDR1"},
{"LOC2", "ADDR2"}
};
//FileB - NameSpace1
Dictionary<string, string> dcB = new Dictionary<string, string>
{
{"LOC3", "ADD3"},
{"LOC4", "ADD4"}
};
//FileX - NameSpace 2
static Dictionary<string, string> dc1 = new Dictionary<string, Dictionary<string, string>>
{
{"LOC1", dcA.GetValue("LOC1"},
{"LOC2", dcA.GetValue("LOC2"},
{"LOC3", dcA.GetValue("LOC3"},
{"LOC4", dcA.GetValue("LOC4"},
};
string myString;
string key = "LOC1";
if (!dc1.TryGetValue(key, out myString))
{
throw new InvalidDataException("Can't find the your Addr for this LOC");
}
Console.WriteLine("myString : {0}", myString)
//Expected output as
myString : ADDR1
Yes i want to combine 2 dictionary to a new dictionary. The problem is i can access value of new dictionary like this dcA.GetValue("LOC1"}. Trying to see if there a better solution or data struct which i'm not thinking at all.