开发者

Why does Resharper rename variables to start with an underscore?

I've never understood this, and frankly, it pisses me off to see it in code: variable names that begin with an underscore.

What is the poi开发者_JS百科nt of this?

I've just installed Resharper 5.1, trying it out and it seems nice, though this one thing is ruining it for me.

I haven't checked, but I'm hoping I can turn it off. But why is it done in the first place?


It's a pretty common style for private fields, some use m_lowerCamelCase, others only _lowerCamelCase and still others lowerCamelCase. For variables inside a functions it's a lot more rare and reshaper by default use lowerCamelCase for them.

Note that the naming section of the design guidelines discourage the use of prefixes for public members but private members are not concerned (And public fields should be used only in really specific cases due to their dangers anyway).

In the reshaper options all of that could be changed in Languages > Common > Naming Style.

You could also save your parameters in the solution or in a file and import/export them. Using that you could set the parameters once and for all for everyone in your team.


Prefixing private instance and/or static members of various kinds with an underscore is a widely-adopted practice ([citation needed], obviously, but it is); this is not the place for me to discuss its rights and wrongs.

In ReSharper | Options you will see Languages | Common | Naming Style (and per-language overrides) that will allow you to instruct ReSharper to do exactly as you wish instead.


It's a common practice to use underscores to denote class variables.

There should be an option in ReSharper to configure what, if anything, you want your class variables to start with. I don't have it installed on this machine so I can't easily check what that option is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜