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# 命名约定?
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
