C#, access child properties from parent reference?

后端 未结 5 932
孤城傲影
孤城傲影 2020-12-21 11:31
public void GetProps(Parent p){

   // want to access lots of child properties here
   string childProp1 = p.prop1;
   bool childProp2 = p.prop2;
   bool childProp3          


        
5条回答
  •  佛祖请我去吃肉
    2020-12-21 11:52

    The solution in case someone need it, it is just to cast the class you receive as a reference as follows:

    public void GetProps(Parent p){
    ..
      string childProp1 = ((ChildClass)p).prop1;   
    ...
    }
    

提交回复
热议问题