enum enum_name{
enumeration list;
}
using System; namespace task.lmcjl.com { class Demo { enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; static void Main(string[] args) { Console.WriteLine("Sun = {0}", (int)Day.Sun); Console.WriteLine("Mon = {0}", (int)Day.Mon); Console.WriteLine("Tue = {0}", (int)Day.Tue); Console.WriteLine("Wed = {0}", (int)Day.Wed); Console.WriteLine("Thu = {0}", (int)Day.Thu); Console.WriteLine("Fri = {0}", (int)Day.Fri); Console.WriteLine("Sat = {0}", (int)Day.Sat); Console.ReadKey(); } } }运行结果如下:
Sun = 0
Mon = 1
Tue = 2
Wed = 3
Thu = 4
Fri = 5
Sat = 6
enum ErrorCode
{
None,
Unknown,
ConnectionLost = 100,
OutlierReading = 200
}
using System; namespace task.lmcjl.com { class Demo { enum Season { winter = 10, spring, summer = 15, autumn }; static void Main(string[] args) { foreach(Season i in Enum.GetValues(typeof(Season))){ Console.WriteLine("{0} = {1}", i, (int)i); } Console.ReadKey(); } } }运行结果如下:
winter = 10
spring = 11
summer = 15
autumn = 16
using System; namespace task.lmcjl.com { class Demo { enum Season { winter = 10, spring, summer = 15, autumn }; static void Main(string[] args) { foreach(String s in Enum.GetNames(typeof(Season))){ Console.WriteLine(s); } Console.ReadKey(); } } }运行结果如下:
winter
spring
summer
autumn
本文链接:http://task.lmcjl.com/news/18299.html