Should a local const variable start with Upper or lower casing

我与影子孤独终老i 提交于 2019-12-10 20:58:43

问题


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 wants 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?


回答1:


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/




回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/3837447/should-a-local-const-variable-start-with-upper-or-lower-casing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!