Reputation: 13
I have a method that looks like following:
method(List<Car> list)
{
}
How do i call a method in main that has a list of Car as parameter?
Upvotes: 0
Views: 82
Reputation: 1062570
by.... creating a list of cars, adding the cars you are interested in, and calling it?
var list = new List<Car>();
list.Add(new Car { Color = "Blue" });
list.Add(new Car { Color = "Green" });
method(list);
The bigger issue, perhaps, is "how do I call a non-static method from a static method such as Main()
", to which there are two possible answers:
static
(if it doesn't need instance state)Assuming we mean the latter:
var obj = new SomeType(); // assuming an accessible parameterless ctor exists
obj.method(list);
Upvotes: 2
Reputation: 1479
Is this not working?
var cars = new List<Car>(); //Get your list of cars
method(cars);
Upvotes: 0