I have a List called
private List<Car> Cars; //Car is another class
I want to create a new list from the information in the List< Car > Cars that uses parameters to specify a year range to extracted from the Cars list and then placed into a new list called
private List<Car> getCars;
The code is as follows. Please note it is only part of a project so not all code is provided.
private List<Car> Cars;
private List<Car> getCars;
public List<Car> GetCars(int fromYear, int toYear)
{
getCars = new List<Car> { };
foreach (Car c in Cars)
if (c.Year >= fromYear && c.Year <= toYear)
getCars.Add(c);
return getCars;
}
The problem I'm having is although there are no errors showing up when I run the code the new list does not print out, instead it print's out
System.Collection.Generic.List'1[Lab__2.Car]
Any help would be great in how to make it print out the list's objects instead of what is above. Finally My lecturer has specified that he wants the method formatted as such
public List<Car> GetPrices(int year)
{
}