R
Robert
Hi,
I have a generic List that holds a type that must inheret from a base
type and implement a interface.
Can I use the generic list without nowing the derived type?
Here is some code to explain the situation (i hope):
namespace Nevermind
{
public abstract class BaseCar
{
public void Start() { }
}
public interface IDoSomething
{
void DoIt();
}
public class CarList<Tcar> : List<Tcar> where Tcar : BaseCar,
IDoSomething
{
}
public class BigCar : BaseCar, IDoSomething
{
public void DoIt()
{ }
}
public class SmallCar : BaseCar, IDoSomething
{
public void DoIt()
{ }
}
public class BuildCars
{
//I want to hold a list with cars, can be smallcars or BigCars
//but the compiler doesn't like this:
CarList<Tcar> cars;
//he doesn't like this either:
CarList<BaseCar> cars;
}
}
Tanx in advance!
I have a generic List that holds a type that must inheret from a base
type and implement a interface.
Can I use the generic list without nowing the derived type?
Here is some code to explain the situation (i hope):
namespace Nevermind
{
public abstract class BaseCar
{
public void Start() { }
}
public interface IDoSomething
{
void DoIt();
}
public class CarList<Tcar> : List<Tcar> where Tcar : BaseCar,
IDoSomething
{
}
public class BigCar : BaseCar, IDoSomething
{
public void DoIt()
{ }
}
public class SmallCar : BaseCar, IDoSomething
{
public void DoIt()
{ }
}
public class BuildCars
{
//I want to hold a list with cars, can be smallcars or BigCars
//but the compiler doesn't like this:
CarList<Tcar> cars;
//he doesn't like this either:
CarList<BaseCar> cars;
}
}
Tanx in advance!