Hello :)
I am trying to do the following in C# 4.0:
I have a Base Class and 2 derived classes
public class Base {}
public class DerivedClass1 : Base {}
public class DerivedClass2 : Base {}
I want to do something like this, but it doesn't work.
How to I tell a Generic List to accept a Base Class and the derived classes of the base class.
public class Class_1
{
public Class_1()
{
List<DerivedClass2> list = new List<DerivedClass2>();
new Class_2(list);
}
}
public class Class_2
{
public Class_2(List<Base> list)
{
}
}
In Java I can do something like this
public class Class_2
{
public Class_2(List<? extends Base> list)
{
}
}
Does something like that exists in C#
I hope my question is clear, its just about the generics of the List.
Thanks a lot in Advance :)