C# naming convention for constants?(常量的 C# 命名约定?)
问题描述
private const int THE_ANSWER = 42;
或
private const int theAnswer = 42;
我个人认为对于现代 IDE,我们应该使用 camelCase,因为 ALL_CAPS 看起来很奇怪.你怎么看?
Personally I think with modern IDEs we should go with camelCase as ALL_CAPS looks strange. What do you think?
推荐答案
推荐的命名和大小写约定是使用 PascalCasing 用于常量(微软有一个名为 StyleCop 记录了所有首选的约定,并且可以检查您的来源是否合规 - 尽管它对于许多人的口味来说有点太保留).例如
The recommended naming and capitalization convention is to use PascalCasing for constants (Microsoft has a tool named StyleCop that documents all the preferred conventions and can check your source for compliance - though it is a little bit too anally retentive for many people's tastes). e.g.
private const int TheAnswer = 42;
微软的 Framework 中也记录了 Pascal 大小写约定设计指南.
这篇关于常量的 C# 命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:常量的 C# 命名约定?


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01