With apologies to patel_vijay for expanding on his solution ...
Quote:
Or you can acess the base class properties in deried class using this or base keyword.
here is an example...
Say you have something set up like
public class OldCar
{
protected int aHiddenProp;
public int AHiddenProp
{
get { return aHiddenProp; }
set { aHiddenProp = value; }
}
}
public class NewCar : OldCar
{
private bool _isAirBag;
public bool IsAirBag
{
get { return _isAirBag; }
set { _isAirBag = value; }
}
public string showValues()
{
base.AHiddenProp = 4;
return _isAirBag.ToString() + ' ' + base.AHiddenProp.ToString();
}
}
then anything creating an instance of the NewCar class can use the underlying base class properties as well...
private void button1_Click(object sender, EventArgs e)
{
NewCar nc = new NewCar();
nc.AHiddenProp = 3;
nc.IsAirBag = true;
MessageBox.Show(nc.showValues());
}
The messageBox will display "True 4" because I've adjusted the value in the showValues function
[Edit]
If you (really) want to pass an instance of OldCar to NewCar then you will have to write an appropriate constructor for NewCar e.g.
public NewCar() { }
public NewCar(OldCar oc)
{
this.AHiddenProp = oc.AHiddenProp;
}
but the better route is just to use NewCar in the first place.
See also
http://msdn.microsoft.com/en-us/library/ms173149.aspx[
^]