RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
十三、流程控制之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://lswzjz.com/article/gdjpii.html