条件语句实例

判断三个数谁对大:

static void Main(string[] args)
        {
            Console.WriteLine("请输入第一个数:");
            int a = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("请输入第二个数:");
            int b = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("请输入第三个数:");
            int c = Convert.ToInt32(Console.ReadLine());


            if (a >= b)
            {
                if (a >= c)
                {
                    Console.WriteLine("三个数最大的是:" + a);
                }

                else
                {
                    Console.WriteLine("三个数最大的是:" + c);

                }

            }
            else
            {

                if (b >= c)
                {
                    Console.WriteLine("三个数最大的是" + b);

                }

                else
                {
                    Console.WriteLine("三个数最大的是" + c);
                }
            }


        }

判断一个数的奇偶性:

 static void Main(string[] args)
        {
            Console.Write("输入一个数:");
            int a = int.Parse(Console.ReadLine());
           
            if (a%2== 0)
            {
                Console.Write("这个数是偶数");
            }
            else 
            {
                Console.Write("这个数是奇数");
            }
            Console.ReadLine();
           
        }  

判断闰年:

static void Main(string[] args)
        {
            Console.WriteLine("请输入年份:");
            int year = int.Parse(Console.ReadLine());
            if (year % 400 == 0 || year % 4 == 0 && year % 4 != 0)
            {
                Console.Write(year + "是闰年");

            }
            else 
            {
                Console.Write(year+"是平年");
            }
        }

移动客服:

static void Main(string[] args)
{
Console.WriteLine("查话费按1,查流量按2,人工服务按3,业务办理按4,");
int a = Convert.ToInt32(Console.ReadLine());


switch (a)
{
case 1:
{
Console.WriteLine("你的话费有点多,禁止充值");
break;
}
case 2:
{
Console.WriteLine("流量还可以支撑");
break;
}
case 3:
{
Console.WriteLine("人工服务全忙,请稍候");
break;
}

case 4:
{
Console.WriteLine("对不起不能办理");
break;
}
default:
{
Console.WriteLine("您输入的有误");
break;
}


}
}

游戏随即英雄选择:

 static void Main(string[] args)
        {
            Random a = new Random();
            int b = a.Next(5);

            string hero;

            switch (b)
            {
                case 1:
                    {
                        hero = "伊泽瑞尔";
                        break;
                    }

                case 2:
                    {
                        hero = "拉克丝";
                        break;
                    }

                case 3:
                    {
                        hero = "盖伦";
                        break;
                    }

                case 4:
                    {
                        hero = "提莫";
                        break;
                    }

                default:
                    {
                        hero = "崔丝塔娜";
                        break;
                    }
            }

            Console.WriteLine("你选的英雄为:" + hero + ",请做好开始准备");
            
        }
原文地址:https://www.cnblogs.com/liuyudong0825/p/4696672.html