How can I put subclasses from the same baseclass into a list?
I´m working with ASP.NET MVC3 and have created a basemodel-class with properties like name, age and so
Just create the list so it's of the base class:
List myList = new List();
then add your subclass objects as normal:
myList.Add(new SubClass1());
myList.Add(new SubClass2());
etc. where:
public class SubClass1 : BaseClass {}
public class SubClass2 : BaseClass {}
Then when you get them out you can use the is and as operators to determine what type they actually are and deal with them as appropriate.