Tag: 常数

如何最好地在C#中实现可公开访问的常量

在C#中实现可公开访问的常量似乎有三种选择。 我很好奇是否有任何理由选择其中一个或者只是个人偏好。 选择1 – 私人领域加上财产吸气剂 private const string _someConstant = “string that will never change”; public string SomeConstant { get { return _someConstant; } } 选择2 – 仅限属性吸气剂 public string SomeConstant { get { return “string that will never change”; } } 选择3 – 仅限公共领域 public const string SomeConstant = “string that will never change”; […]

我可以用C#中的千位分隔符声明常量整数吗?

Cobra编程语言有一个很有用的function,您可以在数字文字中使用下划线来提高可读性。 例如,以下是等效的,但第二行更容易阅读: x = 1000000 x = 1_000_000 # obviously 1 million C#有什么相同的东西吗?

如何定义Visual C#中的常量,如C中的#define?

在C中,您可以定义这样的常量 #define NUMBER 9 因此,无论NUMBER出现在程序中,它都会替换为9.但Visual C#不会这样做。 怎么做?