i have a list with: Circle, Triangle, Rectangle in it
i want to edit the element with the id X but list[X].radius; is not available because it is a child class.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you have a mixed list and want to access members defined for the derived types, you have to cast to the derived type.
Of course, by the virtue of simply having a mixed list, you’re saying that you generally do not care about the differences between the derived types, you’re content with using the base polymorphically. If you find yourself in a different position, you should perhaps rethink your strategy for storing or consuming these elements.