学习枚举与INT型关系:
A.枚举的定义:实际上是为一组逻辑上密不可分的整型值提供便于记忆的符号.
B.枚举值的类型:byte,sbyte,short,ushort,int,uint,long,ulong 8种数值类型,默认是int型.
C.举例:
A.枚举的定义:实际上是为一组逻辑上密不可分的整型值提供便于记忆的符号.
B.枚举值的类型:byte,sbyte,short,ushort,int,uint,long,ulong 8种数值类型,默认是int型.
C.举例:
1class EnumHelper
2 {
3 enum enum1 : int { Saturday = -1, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday }
4
5 public static void main()
6 {
7 Console.WriteLine(enum1.Monday);//Monday
8 Console.WriteLine(enum1.Tuesday.ToString());//Tuesday
9 Console.WriteLine((int)enum1.Thursday);//4
10 }
11 }
2 {
3 enum enum1 : int { Saturday = -1, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday }
4
5 public static void main()
6 {
7 Console.WriteLine(enum1.Monday);//Monday
8 Console.WriteLine(enum1.Tuesday.ToString());//Tuesday
9 Console.WriteLine((int)enum1.Thursday);//4
10 }
11 }