I've got the following code:
public static T GetCar<T>() where T : ICar
{
T objCar = default(T);
if (typeof(T) == typeof(SmallCar)) {
objCar = new SmallCar("");
} else if (typeof(T) == typeof(MediumCar)) {
objCar = new MediumCar("");
} else if (typeof(T) == typeof(BigCar)) {
objCar = new BigCar("");
}
return objCar;
}
And this is the error I am getting: Cannot implicitly convert type 'Test.Cars' to 'T'
What Am I missing here? All car types implement the ICar interface.
Thanks