If i have an accessor and default property in a base class as follows:
class base{
protected int _foo = 5;
public int foo {get{return _foo;}set{_foo = value;}}
}
Then I derive this class, is it possible to override the default value of _foo?
class derived:base{
// foo still returns 5?
protected new int _foo = 10;
}
The _foo = 5 statement effectively executes in the base class's constructor. You can add code to the derived class constructor that changes foo's value immediately afterwards:
class derived:base{
public derived()
{
foo = 10;
}
}
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