首页 > 其他 > 详细

条件与&&与条件或||的使用总结

时间:2015-07-19 09:55:42      阅读:261      评论:0      收藏:0      [点我收藏+]

CSDN说明:

条件“或”运算符 (||) 执行 bool 操作数的逻辑“或”运算,但仅在必要时才计算第二个操作数。

件“与”运算符 (&&) 执行其 bool 操作数的逻辑“与”运算,但仅在必要时才计算第二个操作数

 

同时我们还要了解到  || 和 && 都是左结合性的逻辑运算符,所以看下面的例子

class Program
    {
        static void Main(string[] args)
        {
            int a = 9;
            int b = 10;
            int c = 11;
            int d = 12;
            if (d>b || c > b && a>b)
            {
                Console.WriteLine("true");
            }
            Console.ReadKey();
        }
    }

所以在判断到d>b为true时,后面的部分c > b && a>b就不会再运算,进入条件语句里面

条件与&&与条件或||的使用总结

原文:http://www.cnblogs.com/liuww/p/4658176.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!