资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

十三、流程控制之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://cdkjz.cn/article/gdjpii.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220