十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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(); } } }