[Edit] What I wanted to ask was just putting a class name with this
, so it wasn't about referencing an outer class member. Sorry for my inappropriate example!
[Edit2] Someone reported this as a duplicate BUT NOT! As I said earlier, I just wanted to know if it's possible to reference MyClass.this
and this
interchangeably like in Java. This wasn't a practical question at all but just for learning C# language itself. I don't mind removing this if people really think it's a duplicate so let me know.
In Java, you can use this
with class names like this:
class OuterClass {
int outerMember = 1;
class InnerClass {
int innerMember = 2;
public void printOuterMember() {
System.out.println(OuterClass.this.outerMember);
System.out.println(outerMember);
}
public void printInnerMember() {
System.out.println(InnerClass.this.innerMember);
System.out.println(this.innerMember);
System.out.println(innerMember);
}
}
}
Sometimes class names are not needed, but sometimes helpful.
So I tried the same thing in C# but it seems it's impossible. Am I right?