I\'m trying to pass A list of DerivedClass
to a function that takes a list of BaseClass
, but I get the error:
cannot convert from
A solution i used was to create an extension class:
public static class myExtensionClass
{
public void doSomething(List bc) where T: BaseClass
{
// do something with bc
}
}
It uses generic, but when you call it you don't have to especify the class since you already 'told' the compiler the type is the same of extended class.
You would call it this way:
List lst = new List();
lst.doSomething();