Is there a difference in use or not the keyword "this" to refer to a method within the same class?

Possible duplicate:
When do you use the keyword "this"?

If I have the following example:

public class MyClass {

private void MyMethod1()
{
    ...
}

private void MyMethod2()
{
    this.MyMethod1();
    ...
}

}

In "MyMethod2" is there any difference in using "this.MyMethod1 ()" or just "MyMethod1 ()"? Performance, security, good practice or something else? I ask this because I usually do not use "this" to call methods in the same class, but I get code developed by other people who use it ... maybe I'm wrong ... or not!

Sorry if this looks like a stupid question, but I'm still curious. Thank!

+3
3

, .

this , , .

private void MyMethod2()
{
    Action MyMethod1 = MyMethod2;
    MyMethod1(); // recursive call to MyMethod2

    this.MyMethod1(); // call to real MyMethod1
}

, - , . .

+1

- -.

, , , , this , .

+3

. , , - .

, , .

0
source

Source: https://habr.com/ru/post/1760635/


All Articles