使用if语句

发布于 2012-11-25  27 次阅读


static void Main(string[] args)
{
string comparison; ///声明一个string变量。
Console.WriteLine("Enter a number:");
double var1 = Convert.ToDouble(Console .ReadLine ());
Console.WriteLine("Enter another number:");
double var2 = Convert.ToDouble(Console .ReadLine ());
///从用户输入中得到两个double值。
if (var1<var2 )
comparison = "less than";
else
{
if (var1==var2)
comparison ="equal to";
else
comparison ="greater than";
}
///比较var1和var2,并把一个字符串赋给string变量comparison。
Console .WriteLine ("The first number is {0} to the second number.",comparison );
///输出比较结果。
Console .ReadKey ();
///注:这里if用了嵌套的方式(使执行的代码较少),不用嵌套也可以,不过性能上就……
}

除非注明,本博客所有内容 由 秒速340 创作,采用 知识共享 署名-非商业性使用-禁止演绎 3.0 未本地化版本 许可协议进行许可。