3xodus
Freshman
I have some C++ code that I wrote while at Uni (I'm in a year work placement at the minute) that's along the lines of:
I came back to look at it as it does what I want to do at work in C# - that is to work with either ClassB or ClassC without knowing which, via a pointer of ClassA (which both ClassB and ClassC derive from), upcasted from a ClassB or C instance.
Is this even possible now in C#? I've read a little about how C#'s pointers differ from C++, and it seems not. All 3 classes are will be my own, but would contain managed properties such as strings and integers.
Is there another way I can approach this?
Now sure how well I've explained what I'm trying to do either.
Thanks,
Code:
ClassA* p_classA;
ClassB* p_classB;
ClassC* p_classC;
switch(someInteger)
{
case 1:
p_classB = new ClassB;
p_classA = p_classB;
break;
case 2:
p_classC = new ClassB;
p_classA = p_classC;
break;
(.. and so on..)
}
p_classA->Something();
Is this even possible now in C#? I've read a little about how C#'s pointers differ from C++, and it seems not. All 3 classes are will be my own, but would contain managed properties such as strings and integers.
Is there another way I can approach this?
Now sure how well I've explained what I'm trying to do either.
Thanks,
Last edited: