c# - Accessing derived class property members from base class object in CSharp -


i having trouble accessing property members of derived class using base class object.

scenario:

public class baseclass{     public virtual write(baseclass data){     } }  public class derivedclass : baseclass{      private string name:      public string name {get {return name} set {name = value;} }      public override write(baseclass data){      console.println(data.name);  // gives me error here     }  } 

the reason have problem accessing properties in derived classes base class not (and more importantly should not) know them. different derived classes have different set of added properties. making base class aware of counteract important principles of object oriented design. 1 such principle comes mind liskov substitution principle.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -