VB.net下Enum类型变量可以直接赋值为Int,如
C#下的情况如下
为什么会出现这种情况,难道0不是int类型的,还是0有更多含义?
Module Module1
Public Enum Sex
Male
Female
End Enum
Sub Main()
Dim sex As Sex
sex = 0 'sex值为Male
sex = 1 'sex值为Female
sex = 1000 'sex值为1000
End Sub
End Module
Public Enum Sex
Male
Female
End Enum
Sub Main()
Dim sex As Sex
sex = 0 'sex值为Male
sex = 1 'sex值为Female
sex = 1000 'sex值为1000
End Sub
End Module
namespace AboutEnum
{
class Class1
{
public enum Sex { Male, Female }
[STAThread]
static void Main(string[] args)
{
Sex sex;
sex = 0; //sex值为Male
sex = 1; //提示类型错误
}
}
}
{
class Class1
{
public enum Sex { Male, Female }
[STAThread]
static void Main(string[] args)
{
Sex sex;
sex = 0; //sex值为Male
sex = 1; //提示类型错误
}
}
}