开发者

Should a local const variable start with Upper or lower casing

开发者 https://www.devze.com 2023-01-18 03:21 出处:网络
Got a style conflict between StyleCop and Resharper. Stylecop 1303 says that const vars should start uppercase and I agree.

Got a style conflict between StyleCop and Resharper. Stylecop 1303 says that const vars should start uppercase and I agree. Resharper says OK for class-wide const declarations, but when using a const in a local (e.g. method) scope, Reshaper doesn't approve and 开发者_如何学Gowants to make everything camelCasing.

Of course no problem to disable this rule in R#, but what could be the reason behind this rule? Anyone any thoughts?


If you download Stylecop for Resharper then it comes with a Resharper settings file that will fix this for you. It's also a great way to get Resharper to help you with Stylecop compliance:

http://stylecopforresharper.codeplex.com/


I'd stick to the R# interpretation in this case (on local scope, everything should be lowerCamelCase).

It's largely a matter of habit, because I'm usually starting with a variable, and after I've finished the method, I might change the var to a const, if the respective R# smart tag recommends this to me.

But as pointed out, the important thing is to be consistent across the team...

Thomas


I think StyleCope is using the case to distinguish between class and method scope.


I'm sure almost everyone has thoughts on that, and those are seldom in sync. Find your flavor and stick with it. Re# and the like are suggestions. You and your coworkers should agree on something, that is most important.

0

精彩评论

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

关注公众号