重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

十三、流程控制之if语句

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _13.流程控制之if语句
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * if语句语法及执行过程:
             *  if ()
             *  {
             *       is true>
             *  }
             *  else if ()
             *  {   
             *       is true>
             *  }
             *  ...
             *  else
             *  {
             *       is false>
             *  }
             * 
             */
             
            // 求三个整数中的最大值
            
            // if语句版本
            {
                int a = 6, b = 5;
                string comparison = null;
                if (a > b)
                    comparison = "greater than";
                if (b > a)
                    comparison = "less than";
                if (a == b)
                    comparison = "equal to";
                Console.WriteLine("{0} is {1} {2}", a, comparison, b);
            }
            
            // if_else语句版本
            {
                int a = 6, b = 5;
                string comparison = null;
                if (a > b)
                {
                    comparison = "greater than";
                }
                else
                {
                    if (a < b)
                        comparison = "less than";
                    else
                        comparison = "equal to";
                }
                Console.WriteLine("{0} is {1} {2}", a, comparison, b);
            }
            
            // if_elseif_else语句版本
            {
                int a = 6, b = 5;
                string comparison = null;
                if (a > b)
                {
                    comparison = "greater than";
                }
                else if (a < b)
                {
                    comparison = "less than";
                } 
                else
                    comparison = "equal to";
                Console.WriteLine("{0} is {1} {2}", a, comparison, b);
            }
            
            Console.ReadKey();
        }
    }
}

标题名称:十三、流程控制之if语句
标题网址:http://cqcxhl.cn/article/gdjpii.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP