List<string[]> parent = new List<string[]>();
string[] child = new string[2];
bool isRunning = true;
while (isRunning)
{
Console.Clear();
Console.WriteLine("1: Add to Array with 2 elements");
Console.WriteLine("2: Show all elements");
Console.WriteLine("3: Close program");
string awnser = Console.ReadLine();
switch (awnser)
{
case "1":
Console.WriteLine("Element number 1:");
child[0] = Console.ReadLine();
Console.WriteLine("Element number 2:");
child[1] = Console.ReadLine();
parent.Add(child);
break;
this would cause the list to have the last array value in all list values
List<string[]> parent = new List<string[]>();
bool isRunning = true;
while (isRunning)
{
Console.Clear();
Console.WriteLine("1: Add to Array with 2 elements");
Console.WriteLine("2: Show all elements");
Console.WriteLine("3: Close program");
string awnser = Console.ReadLine();
switch (awnser)
{
case "1":
string[] child = new string[2];
Console.WriteLine("Element number 1:");
child[0] = Console.ReadLine();
Console.WriteLine("Element number 2:");
child[1] = Console.ReadLine();
parent.Add(child);
break;
This would add the new values to the list without replacing it. What is so special about arrays in a list.
I don't know why putting it in the while-loop causes the difference, could someone help me understand why?