2
Answers

Object to type

Bryan Austin

Bryan Austin

17y
1.6k
1
I have 2 data types in an object array. ExampleBase class ExtendedExample class that extends ExampleBase The the ExampleBase class has a virtual Writeout() method that returns a 'string 1'. The the ExtendedExample class also has virtual Writeout() method that returns 'string 2'. Now when I pull both of them out of the array and cast them both as ExampleBase and they both return 'String 1'. Even though when I use GetType() they return both ExampleBase and ExtendedExample respectively. I want to extend several classes off the ExampleBase class without having to write a lot of code assign a data type when I return the value of the Writeout() method. So is there any way to have it write out a different string even though I cast them as the same base type?

Answers (2)