+ 2
What is the Importance of the "this" keyword?
I think "this" keyword is unnecessary. Can we stop redundant use of "this" keyword??
8 ответов
+ 10
Think about This as a reference variable that refers to the current object.
+ 6
I think, no
+ 4
When a method is called, it is automatically passed a reference to the invoking object (that is, the object on which the method is called). This reference is called this.
+ 2
As always, you could pass the object as a parameter and refer to it by referencing that, but "this" makes the code a bit more consistent and easier to read. It very simply indicates that whatever variable or method you're referring to should apply to THIS one... The one that is being referred to in this method's call.
+ 1
Is it possible to stop use of "this" keyword?
0
method(string name) {
this.name = name;
}
method(this)
method(this.var)
operator overloading
initialice inner vars (readability mainly)
0
From stackoverflow.com
To qualify members hidden by similar name
To have an object pass itself as a parameter to other methods
To have an object return itself from a method
To declare indexers
To declare extension methods
To pass parameters between constructors
To internally reassign value type (struct) value.
To invoke an extension method on the current instance
To cast itself to another type
To chain constructors defined in the same class