When should I use “this” in a class?

后端 未结 18 2149
情书的邮戳
情书的邮戳 2020-11-21 23:36

I know that this refers to a current object. But I do not know when I really need to use it. For example, will be there any difference if I use x i

18条回答
  •  清酒与你
    2020-11-21 23:54

    You only need to use this - and most people only use it - when there's an overlapping local variable with the same name. (Setter methods, for example.)

    Of course, another good reason to use this is that it causes intellisense to pop up in IDEs :)

提交回复
热议问题