【发布时间】:2013-02-03 18:51:21
【问题描述】:
我正在寻找关于如何创建类枚举类而不是数字包含字符串值的最佳实践。 像这样的:
public static class CustomerType
{
public static string Type1 = "Customer Type 1";
public static string Type2 = "Customer Type 2";
}
我会在整个应用程序中使用这个类作为我需要 CustomerType 的所有情况的值。我不能使用 Enum,因为这是遗留系统,并且像这样的值在任何地方都是硬编码的,我只是想将它们集中在一个地方。
问题是,在上面的例子中,我应该用它来声明一个变量吗:
- 静态只读关键字
- const 关键字
- 或者只是静态的
设置这些类和值的最佳做法是什么?
【问题讨论】:
标签: c# .net string constants static-members