[ACCEPTED]-C# Can a base class property be invoked from derived class-setter
Accepted answer
EDIT: the revised example should demostrate 2 the order of invocations. Compile as a console 1 application.
class baseTest
{
private string _t = string.Empty;
public virtual string t {
get{return _t;}
set
{
Console.WriteLine("I'm in base");
_t=value;
}
}
}
class derived : baseTest
{
public override string t {
get { return base.t; }
set
{
Console.WriteLine("I'm in derived");
base.t = value; // this assignment is invoking the base setter
}
}
}
class Program
{
public static void Main(string[] args)
{
var tst2 = new derived();
tst2.t ="d";
// OUTPUT:
// I'm in derived
// I'm in base
}
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.