c# - 常量首字母缩略词的命名约定

标签 c# naming-conventions stylecop acronym

根据 StyleCop,常量的命名约定是 Pascal。

例如

private const double InchToMm= 2.54;

首字母缩略词的命名约定如何?

private const int Dpi = 96;

private const int DPI = 96;

最佳答案

Microsoft 的 Framework Design Guidelines 说:

The PascalCasing convention, used for all identifiers except parameter names, capitalizes the first character of each word (including acronyms over two letters in length), as shown in the following examples:

PropertyDescriptor

HtmlTag

A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier:

IOStream

The camelCasing convention, used only for parameter names, capitalizes the first character of each word except the first word, as shown in the following examples. As the examples also shows, two-letter acronyms that begin a camel-cased identifier are both lowercase:

propertyDescriptor

ioStream

htmlTag

但是,这些只是指导方针和惯例,而不是法律。如果您想采用其他约定,请使用它。但是永远不要混淆。

关于c# - 常量首字母缩略词的命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181163/

相关文章:

entity-framework - EF 6、代码第一联结表名称

teamcity - 如何将 StyleCop 与 TeamCity 结合使用

c# - 初始化 MobileServicesClient 的最佳位置

c - C 风格命名约定的要点

c# - 简单注入(inject)器,无法覆盖现有注册

django - 为整个 Django 模型定义一个详细名称

c# - 当我在 VS2010 中使用 WinForms (C#) 设计器时,它仍然生成 StyleCop 提示的代码

.net - 自动 StyleCop

c# - 从 StaticResource 设置 RowDefinition 高度

c# - 如何验证密码包含X个大写字母和Y个数字?