if...else结构就是经常说的“如果……就……否则就……”具体语法下:
if (条件) { 满足条件时执行的语句; } else { 不满足条件时执行的语句; }
提示:if...else判断语句适用于只有两个条件的情况,即或者符合条件,或者不符合。
我们看下面这个例子:
using System; class Hello { public static void Main() { Console.Write("请输入你的名字:"); string str_userName=Console.ReadLine(); if(str_userName=="six"){ Console.WriteLine("您好!{0},哎呀,是您啊! ",str_userName); } else{ Console.WriteLine("{0}是哪棵葱? ",str_userName); } } }