C#小白学习笔记(12)数组和枚举

 class Program
    {
        enum WeekDay  //枚举类型,若enum WeekDay : long 冒号后为指定的类型,默认为int型
        {
            Mon = 1,
            Tus,
            Wed,
            Thu,
            Fri,
            Sat,
            Son
        }

        static void Main(string[] args)
        {
            /* int[] age = { 16, 18, 20, 15 };
            foreach (int value in age)
            {
                Console.WriteLine(value);
            } */

            //数组
            int[] age1 = new int[5] { 12, 13, 14, 15, 16 };
            for (int i = 0; i < age1.Length; i++)
            {
                Console.WriteLine(age1[i]);
            }
            int[,] age2 = new int[3, 6] { { 1, 2, 3, 4, 5, 6 }, { 7, 8, 9, 10, 11, 12 }, { 17, 18, 19, 20, 21, 22 } };
            Console.WriteLine(age2[1,2]);

            //枚举
            Console.WriteLine((int)WeekDay.Mon);

            foreach (int value in Enum.GetValues(typeof(WeekDay))) //typeof获取枚举类型的对象
            {
                Console.WriteLine(Enum.GetName(typeof(WeekDay),value));
                Console.WriteLine(value);
            }
            Console.ReadKey();
        }
    }

 运行结果:

 

posted @ 2020-09-24 09:42  ___lucky  阅读(165)  评论(0)    收藏  举报