• 作者: 秒速340 2012年11月25日星期日

    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用了嵌套的方式(使执行的代码较少),不用嵌套也可以,不过性能上就……
    }

    0 评论

  • - 除非注明,本站采用创作共用版权协议:知识共享许可协议 - 但小说诗词作品采用的是:知识共享许可协议 -
    - Power by Blogger - Template by Johanes Djogan - Modify by miaosu340