第八课

79 阅读2分钟

namespace test1
{
    class Programe9
    {
        enum Role //遵循 大驼峰命名
        {
            射手, 战士, 法师, 坦克, 刺客 //  每个枚举的名字 都对应着一个编号0 开始
        }
        enum Week
        {
            周一,周二,周三,周四,周五,周六,周天
        }
        enum Stat
        {
            ONline,OFFline,Busy
        }

        static void Main(string[] args)
        {
            // (01)枚举 周一到周天 
            /* Week week1 = Week.周一;
             string strweek1 = Convert.ToString(week1);  // 将枚举类型转换成字符串 
             int intweek1 = Convert.ToInt32(week1);  // 将枚举类型转换为整数  --》 输出的是枚举的下标
             Week week2 = (Week)Enum.Parse(typeof(Week), "2");
             Week week3 = (Week)Enum.Parse(typeof(Week), "周三");
             if (week3 == Week.周六)
             {
                 Console.WriteLine("休息日");
             }
             Console.WriteLine(week2); //输出 字符串转化为枚举的下标索引 输出对应的;
             Console.WriteLine(intweek1);// 转换为整数输出
             Console.WriteLine(strweek1); // 转换字符串输出; 
             Console.WriteLine(week1);// 直接输出 */


            /*
                        // 可以将函数中的变量赋值出来  方便进行判断; 
                        Console.WriteLine("请输入用户名");
                        string username = Convert.ToString(Console.ReadLine());
                        Console.WriteLine("请输入密码");
                        int password = Convert.ToInt32(Console.ReadLine());
                        string msg; // 设置一个输出接收返回值
                        static bool isPrme(string username, int password,out  string msg)
                        {
                            if (username == "admin" && password == 1234)
                            {
                                msg = "登陆成功";
                            }
                            else if (username == "admin" && password != 1234)
                            {
                                msg = "密码错误";
                            }
                            else if (username != "admin" && password == 1234)
                            {
                                msg = "用户名错误";
                            }
                            else
                            {
                                msg = "用户名和密码都错误";
                            }
                            return false;
                        }
                        // 可以将函数中的变量赋值出来 
                        isPrme(username, password, out msg);
                        // ref同样还是将函数中的变量的值带出来︰不一样的是在函数可以不用赋值外部接收的变量需要赋初始值
                        // out 可以变量不需要赋值初始值;
                        Console.WriteLine(msg);
            */
            /*        // (3)q青蛙跳楼
                    // 关系式:f(n)=f(n-1)+f(f-2);
                    // 出口 f(1)=1 f(2)=2
                        static int  qinwa(int n)
                        {
                            if (n == 1 && n == 2) return 1;
                            return n = (n - 1) + (n - 2);
                        }

                        Console.WriteLine("请输入青蛙跳几层");
                       int num = Convert.ToInt32(Console.ReadLine());
                        int num1 = qinwa(num);
                        Console.WriteLine("青蛙有{0}种可能",num1);*/


/*            //(4) 汉若塔; 将n 个盘子从xx 移动xx 的;
            Console.WriteLine("请输入有n个盘子");
            int n = Convert.ToInt32(Console.ReadLine());
            static void hanoi(int n, string start, string middle, string end)
        {
                if (n == 1)
                {
                    Console.WriteLine("{0}到{1}", start, end);
                    return;
                }
            hanoi(n - 1, start, end,middle);
            hanoi(1, start, middle, end);
            // 剩下 n-1个盘子 
            hanoi(n - 1, middle, start, end);
        }
            hanoi(n, "a","b", "c");
*/
        


        /*        Role role = Role.刺客;
                    Console.WriteLine(role);*/

        /* 提示用户选择一个qq在线状态,分别有OnLine 1,OffLine 2,Busy 3 3种状态,输入对应
         状态的编号
         打印出您选择的2qq状态是xx(提示: 使用switch)*//*

         Console.WriteLine("请输入状态编号");
        string strnum =Convert.ToString(Console.ReadLine());
         switch (strnum)
         {
             case "1":
                 Console.WriteLine(Stat.ONline);
                 break;
             case "2":
                 Console.WriteLine(Stat.OFFline);
                 break;
             case "3":
                 Console.WriteLine(Stat.Busy);
                 break;                
             default:
                 Console.WriteLine("无状态");
                 break;
         }*/
    }
    }
}