Logical operators in C#

C# has these logical operators, which are given in table with description:

&&Logical AND
||Logical OR
!Logical NOT
&Bitwise logical AND
|Bitwise logical OR
^Biwise logicalĀ  NOT

The logical operators && and || are used when we want to form compound conditions by combining two or more relations. For example:

X < y && y==10

This type of expression combines two or more relational expressions is termed as a logical expression or a compound relational expression. The logical expression given above is true only if both x < y and y ==10 are true. If either (or both) of them are false, the expression is false. Like the simple expression, a logical expression also yields a value of true or false according to given truth table:

Expression 1Expression 2Expression 1 && Expression 2Expression 1 || Expression 2
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse

One thought on “Logical operators in C#”

  1. How can I use the AND and OR operator in single expression.
    Please provide me an example in vb.net.

    Thanks in advance..

Comments are closed.