Possible Duplicate:
When do you use the “this” keyword?
If I have the following example:
public class MyClass {
private void MyMethod1()
{
...
}
private void MyMethod2()
{
this.MyMethod1();
...
}
}
In the “MyMethod2” is there a difference in use “this.MyMethod1()” or just “MyMethod1()”? Performance, security, good practice, or whatever? I ask this, because normally I don’t use “this” to call methods in the same class, but I get code developed by other people that use it… maybe I’m wrong… or not!
Sorry if looks like a silly question, but I’m “curious” after all. Thank you!
Not performance, they will compile to the same IL.
The thing with the
thiskeyword is that it you don’t have local variables with the same naming as the class members.Other than that some people like it, some does not. Follow the code standard in your team.