samedi 23 juillet 2016

nested class cant call parent class in C# but it can in java

if I have parent class that has a nested class. Then in Java the nested class can call a method in its parent class. but in C# you cant do that and it complains saying "cant call outer class method that is not static".

Any reason for why the behaviour is difference?

PS: I am a java programmer and learning C# so excuse my limited knowledge

Example:

public class parent{

  void methodA(){   }


  public class nested{
    void methodB(){
         methodA();   /// <-- not allowed in C# but good in java
     }  
   }
}

Aucun commentaire:

Enregistrer un commentaire