十三、流程控制之if语句-成都快上网建站

十三、流程控制之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语句
网页URL:http://kswjz.com/article/gdjpii.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流