C # "this" overuse?

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

I am writing part of my first C # code, and I notice what is this.fooneeded only if the local name foois different from this.foo. I still disagree on whether I use this.

Is it always preferable to use thisor is it desirable to use thisonly when necessary?

+3
source share
7 answers

I use only thiswhen necessary. In most cases, I don’t have to distinguish between a local and a class variable, so I just don’t worry if there is no need.

+5

'this', Visual Studio Intellisense. , - 'this' .

+1

. this , , - local, , .

, , local, -, - , , - .

+1

- . , StyleCop ( :)).

StyleCop "his" ?

0

. , , , .

0

this, .

, , IDE Visual Studio ( ), . this.

, this, intellisense , , intellisense.

0
source

Just to give an answer that contrasts with many “about it” answers ...

I almost never use it this. I prefix all member variables with an underscore, and therefore I can easily separate local and member variables. I find that using it thisall the time really pollutes the code and makes it more noisy.

0
source

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


All Articles