枚举简单应用 do while

 private void button1_Click(object sender, EventArgs e)
        {
            int k = (int)DateTime.Now.DayOfWeek;
            switch (k)
            {
                case (int)MyDate.Sun:
                    label1.Text = "星期日";
                    break;
                case (int)MyDate.Mon:
                    label1.Text = "星期一";
                    break;
                case (int)MyDate.Tue:
                    label1.Text = "星期二";
                    break;
                case (int)MyDate.Wed:
                    label1.Text = "星期三";
                    break;
                case (int)MyDate.Thi:
                    label1.Text = "星期四";
                    break;
                case (int)MyDate.Fri:
                    label1.Text = "星期五";
                    break;
                case (int)MyDate.Sat:
                    label1.Text = "星期六";
                    break;
            }

        }
        enum MyDate
        {
            Sun=0,
            Mon=1,
            Tue=2,
            Wed=3,
            Thi=4,
            Fri=5,
            Sat=6
        }

// do while

 Console.WriteLine("****猜数字游戏****");
            Console.Write("请输入一个1至20的整数数:");
            Random r = new Random();							//实例化Ramdom
            int i = r.Next(1, 20);
            float j = float .Parse(Console.ReadLine());				//从键盘上获取j的值
            do												    //开始循环
            {
                if (j == -1)									//如果j==-1执行下面语句
                {
                    Console.WriteLine("请输入整数");
                    j = int.Parse(Console.ReadLine());			//从键盘上获取j的值
                }
                else if (j < i)
                {
                    Console.WriteLine("对不起,猜错啦!太小了,请继续猜可能的数:");
                    j = int.Parse(Console.ReadLine());
                }
                else
                {
                    Console.WriteLine("对不起,猜错啦!太大了,请继续猜可能的数:");
                    j = int.Parse(Console.ReadLine());
                }
            } while (i != j);									//计算do while表达式的值
            Console.WriteLine("真行,猜对啦!");
            Console.ReadLine();


你可能感兴趣的:(C#基础)