Possible Duplicate:
When do you use the “this” keyword?
Hi All,
I am just wondering when and where using the keyword is a MUST? Because sometimes if I dont “this” or even I delete “this” the program just runs fine. So what will happen if you dont use it? or if you USE it in a wrong place.
Some explict examples would be appriciated.
The
thiskeyword is often used to disambiguate between member variables and local variables:The other use of
thisis to pass a reference to the current object so:Another use (Thanks to HadleyHope ) is to disambiguate when method parameters are assigned to member variables with the same name: