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# 命名约定?
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
