- class Program
- {
- enum Days { Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };//默认情况下,枚举中每个元素的基础类型是 int.首位的值不设置就为0,+1递增
- enum Months : byte { Jan = 1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, };// 可以使用冒号指定另一种整数值类型.仅限于long、int、short、byte
- static void Main(string[] args)
- {
- #region 输出值
- Days today = Days.Monday;
- int dayNumber = (int)today;
- Console.WriteLine("{0}是星期{1}", today, dayNumber);
- Months thisMonth = Months.Jul;
- int monthNumber = (int)thisMonth;
- Console.WriteLine("{0}是{1}月", thisMonth, monthNumber);
- Days meetingDay = Days.Friday;
- int meetingNumber = (int)meetingDay;
- Console.WriteLine("会议时间是星期{0}", meetingNumber);
-
- meetingDay = Days.Saturday;
- meetingNumber = (int)meetingDay;
- Console.WriteLine("会议时间改为星期{0}", meetingNumber);
- }
- }
- #endregion
复制代码
我定义的枚举Days中最后没有逗号,枚举Months中最后有逗号,运行之后没有错误,而且也能被使用。
所以有没有, 都一样。 |