0

The console doesn't write the items in the list. I am trying to add input from user to a list then write to the screen. So once i add input to the list i would want it to print to the screen.

ArrayList list = new ArrayList();

 switch (userInput)
        {

            case "Add":
                {
                    Console.WriteLine("Enter Fullname: ");
                    Console.ReadLine();
                    list.Add(Console.ReadLine());

                    display();
                    break;
                }


            case "List":
                {

                    foreach (string item in list)
                    {

                        Console.WriteLine(item);
                    }
                    display();
                    break;
                }

        }
eyedfox
  • 714
  • 1
  • 7
  • 14

2 Answers2

0

You need to assign to a variable and then add

string line = Console.ReadLine();
list.Add(line);
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

When you write:

ArrayList list = new ArrayList();

you delete all the elements in the ArrayList.

You didn't post how do you get to the "List" section after insertion the elements...

also you sholud delete the first

Console.ReadLine();
Moshe D
  • 768
  • 1
  • 4
  • 13