Reputation: 3
good morning,
I have several objects that inherit from my father's class "books" and I need to put them all in an array.
creating an array probe of the parent class and it worked but want to access methods in inherited classes is not possible.
thank.
Upvotes: 0
Views: 337
Reputation: 113242
As much as possible, avoid having to access the methods in the derived classes anyway. A good design would pass such an array of "books" to methods that dealt with "books", and didn't care that they were actually "textbooks" or that some of their methods were overridden.
If unavoidable, you can do:
Textbook tb = myBook as Textbook; if(tb != null) tb.TextbookOnlyOperation();
Upvotes: 1