I would like to use a function that has a parameter of type A. I would like to pass it a class B which derived from A. But C# does not want to.
class A
{
int m_a;
}
class B : A
{
int m_b;
}
void ShowandEditData( ref A _myvar)
{
...
}
Now, i would like to do something like this:
B myB = new B();
ShowandEditData(ref myB);
I have tried many things like casting or using the base
attribute. I guess I'm doing it wrong.
Is it possible to do that with C#?
--Code Edited due to pseudocode creating confusion . (sorry, first post)
just remove the ref
from your method declaration. Like so:
void ShowData(A _myvar)
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With