+ 2

What is the Importance of the "this" keyword?

I think "this" keyword is unnecessary. Can we stop redundant use of "this" keyword??

18th Oct 2016, 11:45 AM
Md. Boshirul Islam Khan
Md. Boshirul Islam Khan - avatar
8 Respostas
+ 10
 Think about This as a reference variable that refers to the current object.
18th Oct 2016, 2:23 PM
Remmae
Remmae - avatar
+ 6
I think, no
19th Oct 2016, 5:12 AM
Remmae
Remmae - avatar
+ 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.
10th Dec 2016, 6:27 PM
Paras Jain
Paras Jain - avatar
+ 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.
25th Nov 2016, 5:45 PM
Matthew Shephard
Matthew Shephard - avatar
+ 1
Is it possible to stop use of "this" keyword?
19th Oct 2016, 4:11 AM
Md. Boshirul Islam Khan
Md. Boshirul Islam Khan - avatar
0
method(string name) { this.name = name; } method(this) method(this.var) operator overloading initialice inner vars (readability mainly)
25th May 2020, 9:04 PM
Kiwwi#
Kiwwi# - avatar
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
25th May 2020, 9:17 PM
Kiwwi#
Kiwwi# - avatar