difference between & and && in .net?
difference between & and && in .Net?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jun 23, 2013, 11:18 PM
hi,
&& is also called "short-circuiting" logical operators.
&& is used to perform AND operation.it is generally used with IF condition. In this case of &&, if the first operand condition is false, then it doesn't bother evaluating the second operand condition.
& is called bitwise logical operation. in this case both Conditions are always execute.
hope this will help you.
VulpesPosted Jun 23, 2013, 10:51 AM
1. In the case of the & operator, both operands are always evaluated.
2. In the case of the && operator, the second operand is only evaluated if the first operand evaluates to 'true'.
For this reason, && is known as a 'short-circuiting' operator because it avoids a potentially unnecessary step and is nearly always preferred in practice.
However, on rare occasions evaluating the second operand may have a side effect which will not take place if the first operand is false. This can occur if the second operand involves a method call or property access.
So, if you're relying on this side effect you should use & rather than && though such programming is generally regarded as poor practice in a high level language such as C#.
Sunny SharmaPosted Jun 23, 2013, 7:42 AM
& is a bitwise operator where as && is a logical operator.
Bitwise operators can operate on both -Integer & Boolean arguments where as Logical operators can operate only on Boolean arguments.
Hope you got the point.
Mark it as answer if it helps.
Cheers!