order - Does c# support chaining && in an if statement or do they have to be nested? -


this question has answer here:

if use following code,

if (obj.contactdetail != null && obj.contactdetail.id != guid.empty) 

will null reference error on second half (.id) or behave javascript , fall out of if on first half of comparison.

i know has been answered, don't know terms use up. sry.

that's called short-circuit evaluation , yes, && operator evaluates second condition if first not false.

msdn:

the conditional-and operator (&&) performs logical-and of bool operands, only evaluates second operand if necessary.

the operation x && y corresponds operation x & y except if x false, y not evaluated, because result of , operation false no matter value of y is. this known "short-circuit" evaluation. conditional-and operator cannot overloaded, overloads of regular logical operators , operators true , false are, restrictions, considered overloads of conditional logical operators.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -