天天看点

c#中Enum 的遍历

大厦法定

class Program
    {

        enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
        enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
        [FlagsAttribute]
        enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

        static void Main(string[] args)
        {

            
            Type weekdays = typeof(Days);
            Type boiling = typeof(BoilingPoints);

            Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");

            foreach (string s in Enum.GetNames(weekdays))
                Console.WriteLine("{0,-11}= {1}", s, Enum.Format(weekdays, Enum.Parse(weekdays, s), "d"));
          

           
            Console.ReadKey();

        }
    }
           

首先是第一个函数  enum.Format()

enumType
要转换的值的枚举类型。
value
要转换的值。
format
要使用的输出格式。

返回值

Type:

value 的字符串表示形式。

这是在公司中写的,因为网速太慢查找资料都要等好久。所以先写到这里啦

c#