-2
 static class ListTest
    {
        static List<string> _list; // Static List instance

        static ListTest()
        {
            
            // Allocate the list.
            
            _list = new List<string>();
        }
        public static void DisplayTest(string SeatsInput)
        {
            _list.Add(SeatsInput);
        }
        public static void DisplayStuff()
        {
            //
            // Write out the results.
            //
            foreach (var value in _list)
            {
                Console.WriteLine("Your seats are" +value);
            }
        }

    }


static string CustomerChooseSeats()
    {
       
        Console.WriteLine("\n\nWhich seats would the customer like to seat?: ");
        string SeatsInput = Console.ReadLine();
        return SeatsInput;
    }


//AND THEN IN THE MAIN 
string SeatsInput = CustomerChooseSeats()

DisplayStuff()

I just started learning C# and trying to make a project based on the Cinema app. I can't seem to figure out how to store data after the input from 'string SeatsInput' into and then print out the values of the lists into a method?

Any suggestions?

2 Answers2

0

Call methods in main this way :

var seatsInput = CustomerChooseSeats();
ListTest.DisplayTest(seatsInput);
ListTest.DisplayStuff();
AVTUNEY
  • 923
  • 6
  • 11
0

Please don't use static like this, it's a really bad habit to get into. If you take static off both methods, you can have your main like

var seatManager = new ListTest();
seatManager.DisplayTest(CustomerChooseSeats())
seatManager.DisplayStuff();

More reading on why not to use static everywhere at this answer.

Chuck
  • 1,977
  • 1
  • 17
  • 23