First I have a parent class:
public class Father {
}
And these are two classes that inherit from Father. But it Method_Abelongs only Child_Ainstead Child_B.
public class Child_A : Father {
public void Method_A { ... }
}
public class Child_B : Father {
}
Finally, I am trying to create a variable that can be dynamically assigned
public class MyClass {
public Father dynamicObject;
public void MyMethod {
dynamicObject = new Child_A();
if (...) {
dynamicObject.Method_A();
}
}
The error as shown below:
The type Father does not contain a definition for Method_A, and the extension method Method_A of type Father cannot be found. Are you missing an assembly link?
I tried type varfor dynamicObject, but we have to set the type varin local area.
public class MyClass {
public var dynamicObject;
}
source
share