Premise: Array in bedded in List. User input to array within list, loop 3 strings within array, choose to loop again to create another array within loop. Print list and array with in. What happens/problem: when choosing to create another loop "array" , the second loop "array" overrides value of first loop"array". If first array was given value a,b,c and second loop/array has value d,s,g. When i print it the second array has overridden first array. Prints first array: d,s,g second array d,s,g.
How can i create new arrays within List as many times as the user wants?
List<string[]> Loggbok = new List<string[]>();
string[] input = new string[3] ;
bool tr = true;
while (tr)
{
Console.WriteLine("Gör en ny Logg inlägg");
for (int i = 0; i < 3; i++)
{
string Object = Console.ReadLine();
input[i] = Object;
}
Loggbok.Add(input);
Console.Write("Make a nother array press: j if not inputn : ");
string val = Console.ReadLine();
if (val == "j")
{
tr = true;
}
else
{
tr = false;
}
}
Console.WriteLine(Loggbok[0][0]); //print first array in list
Console.WriteLine(Loggbok[0][1]);
Console.WriteLine(Loggbok[0][2]);
Console.WriteLine(Loggbok[1][0]); //print second array in list
Console.WriteLine(Loggbok[1][1]);
Console.WriteLine(Loggbok[1][2]);
Console.ReadLine();