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# 命名约定?


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01