快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

十三、流程控制之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://6mz.cn/article/gdjpii.html

其他资讯