0

I have a class like that:

public class A{
 //some properties
}

public class B : A{
   //some more properties
}

public class C : A{
   //some more properties
}

I would like to make a list of B, C and so on like that:

List<A> mylist = new List<A>()
mylist.add((B)someobject);
mylist.add((C)someobject);

If I add B, C etc. type of elements to mylist, It will cast them to type A. Therefore if I want to get properties of mylist[0] it gives me only class A properties.

How can I solve the problem and reach B or C type properties too?

Maksim Simkin
  • 9,561
  • 4
  • 36
  • 49
TTwi
  • 31
  • 4

0 Answers0