You don't need to use
this
in this case, but you need to be aware of it and understand what is it.
How do you think a non-static (instance) method or property access the instance members? This is because the instance method has one more "hidden" parameter which is
this
— a reference to the instance itself. You can explicitly use is, pretty much as if you had an explicit parameter referencing some other instance:
class MyClass {
internal MyClass(MyClass other) { this.MyMember = other.MyMember; }
static void DemoStatic(int someParameter) {
MyStaticMember = someParameter;
}
int MyMember;
static int MyStaticMember;
}
In the example above you don't need
this
. There are cases where it is a must. It happens when one name hides identical name of the member/variable:
class MyClass {
internal MyClass(int A, int B) {
this.A = A;
this.B = B;
}
int A, B;
}
[EDIT]
The run-time type of the variable passed as
this
becomes fundamental to OOP: when a method is virtual, this run-type type is different from the compile-time type of it which is the type of the declaring class. This opens the road to
late binding and, hence,
polymorphism.
See:
http://en.wikipedia.org/wiki/Late_binding[
^],
http://en.wikipedia.org/wiki/Dynamic_dispatch[
^],
http://en.wikipedia.org/wiki/Polymorphism_(computer_science)[
^].
Any questions?
—SA