I am making lists in three dimensions. If I run my code it shows the following strings: list5 + list3 + list1. Now this is in three dimensions, so each dimension adds a word. If you look to the code there will be displayed: 4*4*4 = 64 possiblities. Now I want to add something to the second dimension: testing1 and testing2:
SecondDimonsion.Add("testing1");
SecondDimonsion.Add("testing2");
I dont want the result of testing to interact with List5
. I do want them to interact with List1
tho.
So the outcome would be:
Hello1testing1
Hello2testing1
Hello3testing1
Hello4testing1
Hello1testing2
Hello2testing2
Hello3testing2
Hello4testing2
So in total it would print 64 + 8 possibilities.
Its a hard question to explain and probably even harder to understand. I would love to edit my question if anyone doenst understand the concept.
Thanks in advance!
List<string> List1 = new List<string>();
List<string> SecondDimonsion = new List<string>();
List<string> List5 = new List<string>();
List<string> List3 = new List<string>();
List<List<List<string>>> List6 = new List<List<List<string>>>();
List1.Add("Hello1");
List1.Add("Hello2");
List1.Add("Hello3");
List1.Add("Hello4");
List3.Add("123");
List3.Add("456");
List3.Add("789");
List3.Add("000");
List5.Add("white");
List5.Add("green");
List5.Add("yellow");
List5.Add("black");
SecondDimonsion.Add("testing1");
SecondDimonsion.Add("testing2");
for (int i = 0; i < List1.Count; i++)
{
List<List<string>> List2 = new List<List<string>>();
for (int j = 0; j < List3.Count -2;j++)
{
List<string> List4 = new List<string>();
for (int k = 0; k < List5.Count; k++)
{
List4.Add(List1[i] + List3[j] + List5[k]);
}
List2.Add(List4);
}
List2.Add(SecondDimonsion);
List6.Add(List2);
}
for (int k = 0; k < List1.Count; k++)
{
for (int i = 0; i < List3.Count -2; i++)
{
for (int j = 0; j < List5.Count; j++)
{
Console.WriteLine(List6[k][i][j]);
}
Console.WriteLine(List6[k][i]);
}
}
It looks like you're building 2 lists. The first one is 3d and the other is 2d. I would split it up like this:
If you change your last loop to:
You will see that what you wrote actually does add SecondDimension's values to your list. Since
List6[x].Count > List3.Count
the loops never got there though. However you still haven't appended anything to them so you won't quite get the result you wanted.Here is a fiddle you can play around in.