I have 100 classes that will inherit 1 base class. Derived class can have A
and B
property, just A
or B
property, or don't have them at all. I need a pointer, from derived class to base class, that will trigger every time I call A
or B
property from derived classes.
class D1 : Base
{
int A { get; set; } // Point to Base A
}
class D2 : Base
{
int A { get; set; } // Point to Base A
int B { get; set; } // Point to Base B
}
class Base
{
int A => ExampleA();
int B => ExampleB();
int ExampleA()
{
return 10;
}
int ExampleB()
{
return 15;
}
}
static void Main(string[] args)
{
D1 d1 = new D1();
D2 d2 = new D2();
d1.A; //return 10
d2.A; //return 10
d2.B; //return 15
}
Aucun commentaire:
Enregistrer un commentaire