C# enum

static void Main(string[] args)
        {
            string[] enumNames = GetEnumNames(typeof(Seasons));
            if(enumNames!=null && enumNames.Any())
            {
                foreach(var name in enumNames)
                {
                    Console.WriteLine(name);
                }
            }

            Console.WriteLine(GetEnumName(typeof(Seasons), 1));
            Console.ReadLine();
        }

        static string[] GetEnumNames(Type enumType)
        {
            string[] enumNames = Enum.GetNames(enumType);
            return enumNames;
        }

        static string GetEnumName(Type enumType, int intValue)
        {
            return Enum.GetName(enumType, intValue);
        } 

 

posted @ 2020-01-03 14:59  FredGrit  阅读(269)  评论(0编辑  收藏  举报