命名局部常量:UpperCamelCase或lowerCamelCase? [英] Naming local constants: UpperCamelCase or lowerCamelCase?
问题描述
你使用哪种命名约定的局部常量在 C#?为什么?
Which naming convention do you use for local constants in C# and why?
const int Pi = 3;
const int pi = 3;
看来权衡下驼峰之间显示的限制范围,上驼峰是更容易阅读和移动到一流水平。我注意到的了StyleCop 喜欢上驼峰。
推荐答案
我已经习惯了大写(Pascal大小写)以外的变量和字段的一切。全局常量是一个例外的领域,我不知道为什么,可能是因为他们在某些情况下公开。局部常量也是小写左右。
I'm used to upper case (pascal case) for everything except variables and fields. Global constants are an exception to the fields, I don't know why, probably because they are public in some cases. Local constants are also lowercase so.
这只是一个品味的问题海事组织。当然,一个产品/团队中,应该有一个协议。
It's just a matter of taste imo. Of course, within a product / team, there should be an agreement.
在另一方面,我们的编码准则要求对常量全大写,这将是 PI
在这种情况下。我不喜欢这样,因为上部案件难以阅读,需要强调的分离(这是针对代码分析规则)。没有人遵循本准则了。
On the other hand, our coding guideline requires full uppercase for constants, this would be PI
in this case. I don't like this because upper cases are hard to read and need underlines for separation (which is against code analysis rules). Nobody follows this guideline anymore.
这篇关于命名局部常量:UpperCamelCase或lowerCamelCase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!