下午好,在C#铸造,让我们说我有枚举使用整数枚举不
public enum Test : int
{
TestValue1 = 0,
TestValue2,
TestValue3
}
为什么我不能使用像Int32 IntTest = Test.TestValue1
语句不进行强制转换意味着IntTest = 0
?如果我稍后决定向枚举中添加更多项目,这将会非常有用。我想我不得不使用Int32 IntTest = (Int32) Test.TestValue1
,我认为应该是多余的......还有,为什么我不能让像
switch (IntTest)
{
case (Test.TestValue1) : DoSomething();
break;
case (Test.TestValue2) : DoSomethingElse();
break;
default : Do Nothing();
}
?编译器说,它期望在TestValue1
的地方有一个恒定的值......这个值是不是恒定的?
非常感谢。
不应该是'case(Test.TestValue1)''而不是'case(TestValue1)'吗?你想与枚举进行比较,对吧? – 2010-11-22 15:44:39