I have a Dictionary which contains string and structure in the below format
Dictionary<string, List<Structure>> myDic = new Dictionary<string, List<Structure>>();
string[] tests = new string[] { "test", "test2", "test3", "test4" };
foreach (string test in tests)
{
myDic.Add(value, new List<Structure>{ });
}
struct Structure
{
string name1;
string name2;
}
From the below code, I am printing 2 things
One is key (from list of "tests") and the other is the outputs that I have generated through different part of the code which is not mentioned here
for (int p=0; p< myDictionary.Keys.Count; p++)
{
string key = myDictionary.ElementAt(p).Key;
Console.WriteLine("The output Key is: " + key);
for (int q = 0; q < myDictionary.ElementAt(p).Value.Count; q++)
{
string value = myDictionary.ElementAt(p).Value.ElementAt(q).name2;
Console.WriteLine("The output value is: " + value);
}
}
The output of the code goes as follows (I am iterating through count of "tests")
for iteration0:
The output key is: test1
The output value is: A
for iteration1:
The output key is: test2
The output value is: A
The output value is: B
for iteration2:
The output key is: test3
The output value is: A
The output value is: E
The output value is: F
for iteration3
The output key is: test4
The output value is: A
REQUIRED ALGORITHM:
Since A is present common in all iterations for test1, test2, test3 and test4
Output should be A for all the test1, test2 and test3, test4
If suppose iteration3 doesn't have A,
then output should be A for test1, test2 and test3 and test4 should return an exception
What I have tried:
I have tried few things but couldn't get it right