I have a few classes: class Vehicle { }
class Car : Vehicle
{
}
I have a list of the derived class:
IList<Car> cars;
I would like to convert the list to its base class, and have tried:
IList<Vehicle> baseList = cars as IList<Vehicle>;
But I always get null
. Also
cars is IList<Vehicle> evaluates to be false.
Granted, I can add the items to a list if I do the following:
List<Vehicle> test = new List<Vehicle> ()
;
foreach ( Car car in cars )
{
test.Add(car);
}
And I get my list, but I know there has to be a better way. Any thoughts?