相关疑难解决方法(0)

常量的C#命名约定?

private const int THE_ANSWER = 42;
Run Code Online (Sandbox Code Playgroud)

要么

private const int theAnswer = 42;
Run Code Online (Sandbox Code Playgroud)

我个人认为在现代IDE中我们应该使用camelCase,因为ALL_CAPS看起来很奇怪.你怎么看?

c# const naming-conventions

391
推荐指数
9
解决办法
18万
查看次数

定义局部变量const与类const

如果我使用仅在方法中需要的常量,最好在方法范围内或类范围内声明const吗?是否有更好的性能在方法中声明它?如果这是真的,我认为在类范围(文件顶部)定义它们以更改值并更容易重新编译更为标准.

public class Bob
{
   private const int SomeConst = 100; // declare it here?
   public void MyMethod()
   {
      const int SomeConst = 100; // or declare it here?
      // Do soemthing with SomeConst
   }
}
Run Code Online (Sandbox Code Playgroud)

.net c# jit const

47
推荐指数
3
解决办法
1万
查看次数

标签 统计

c# ×2

const ×2

.net ×1

jit ×1

naming-conventions ×1