0

Java Pseudo Code

public class Foo{
    public void doStuff(){
        System.out.println("Kill all humans...");
    }
    public class Bar{
        public Bar(){
            Foo.this.doStuff();
        }
    }
}

You can have a nested class access it's outer class instance through <Class Instance>.this, to look properties or variable values or even invoke methods if you wanted WITHOUT having to pass a reference of the outer class instance to the inner class instance (I'm assuming that is the anonymous part?).

Does C# have something equivalent?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Will
  • 3,413
  • 7
  • 50
  • 107
  • You can write Foo.doStuff() if doStuff method will be static – teo van kot Jan 09 '15 at 23:43
  • yeah but in my case neither the parent nor the child class will be static, nor will any of their variables or what have you. – Will Jan 09 '15 at 23:44
  • This is not a parent-child relationship. This is an outer-inner class relationship. Parent-child refers to inheritance. – Jeroen Vannevel Jan 09 '15 at 23:45
  • I will edit, thank you. – Will Jan 09 '15 at 23:45
  • Additionally to duplicate, http://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class covers difference between nested (no direct C# equivalent) vs static nested (close to C# nested class) in Java. – Alexei Levenkov Jan 09 '15 at 23:49
  • Side note: There is generally no need to express additional emotions (especially in ALL CAPS) in SO questions unless it directly related to problem. – Alexei Levenkov Jan 09 '15 at 23:53

0 Answers0