[Solved] Cannot reach list in other class in main class


The error is telling you that vluchtList has not been defined.

In your line “foreach (Vluchten Vluchten in vluchtList)”, you are trying to access something called vluchtList that the compiler doesn’t know about.

Before you can use vluchtList, you will need to define it. It looks like it’s supposed to be a list, so try this before the above line:

List<Vluchten> vluchtList = new List<Vluchten>();

This will define the variable to the type List, meaning a list of Vluchten objects.

While that’s good, your foreach loop will not appear to do anything with it, because it is empty, so you will probably want to fill it with some Vluchten data:

vluchtList.Add(new Vluchten
{
    FlightNr = "My Flight Number";
    FlightCarrier = "My Flight Carrier";
    Destination = "My Destination";
    maxPassagers = 200;
    bookedPassagers = 130;
});

This is only adding one Vluchten object to the list, but you can add many.

2

solved Cannot reach list in other class in main class