jeudi 29 novembre 2018

Instantiate the parent class in a child class method

public class C1 {
    public virtual void A() {}
    public void B() {}
}

public class C2 : C1 {
    public override void A()
    {
        C1 temp = new C1();
        temp.B();
    }
}

How can I create temp without explicitly referring to C1 by name? I want to use something similar to base to refer to the parent of C2 regardless of what that parent's name is.





Aucun commentaire:

Enregistrer un commentaire