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 on. Now i have created submodels (subclasses) with more details.
To easily handle the subclasses i want a list with the objects in it but how?
I have read about interfaces or ICollection and so on but don´t know what´s the right choice and how to start 🙁
Just create the list so it’s of the base class:
then add your subclass objects as normal:
etc. where:
Then when you get them out you can use the
isandasoperators to determine what type they actually are and deal with them as appropriate.