I have a set up like this:
abstract class Foo {}
class Bar : Foo {}
and a method elsewhere of this form:
void AddEntries(List&l
This is not allowed for a simple reason. Assume the below compiles:
AddEntries(new List());
void AddEntries(List list)
{
// list is a `List` at run-time
list.Add(new SomethingElseDerivingFromFoo()); // what ?!
}
If your code would compile, you have an unsafe addition (which makes the whole generic lists pointless) where you added SomethingElseDerivingFromFoo
to actually a List
(runtime type).
To solve your problem, you can use generics:
void AddEntries(List list) where T:Foo
{
}