I implement a WindowsForms application in Visual Studio. Now I have a list of toys:
List <Toy> toys;
Toy
is an abstract class, and classes like Car
, Submarine
etc. derive from it. The list can of course contain any object of type Toy
. Due to my lack of experience in C#, I'm not sure how can I modify an object from this list, i. e. change a property that is type-specific. The compiler only knows the list contains Toy
objects, and has no access to fields of a Submarine
object. So I cannot simply take some element from the list, call a setter and be done with it. Casting will only get me a copy of the list object cast to some type. How can I achieve this?