Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Logical Operators | Control Structures
course content

Зміст курсу

C# Basics

Logical OperatorsLogical Operators

Logical Operators can be used for combining two logical expressions or logical values. Following are the three logical operators:

OperatorOperation
&&AND
||OR
!NOT

Note

An operand refers to a value or expression that is used as an input for an operator in a statement or expression. For-example in the expression 1 + 2, the values 1 and 2 are operands. In the case of logical operators, an operand is always a boolean expression or value.

The AND (&&) operator takes two operands and returns true only if both the operands are true. It is demonstrated by the following code:

cs

main.cs

Instead of directly using the true and false literals (values), we commonly use expressions:

cs

main.cs

The OR (||) operator returns true if any one of the operands is true:

cs

main.cs

Following is an example which uses the OR (||) operator:

cs

main.cs

The NOT (!) operator simply negates (inverts) the logical expression or logical value. So if an expression returns true, it changes it into false.

cs

main.cs

What is the expression (0 < 5 || 5 < 10) equal to?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 3. Розділ 2
course content

Зміст курсу

C# Basics

Logical OperatorsLogical Operators

Logical Operators can be used for combining two logical expressions or logical values. Following are the three logical operators:

OperatorOperation
&&AND
||OR
!NOT

Note

An operand refers to a value or expression that is used as an input for an operator in a statement or expression. For-example in the expression 1 + 2, the values 1 and 2 are operands. In the case of logical operators, an operand is always a boolean expression or value.

The AND (&&) operator takes two operands and returns true only if both the operands are true. It is demonstrated by the following code:

cs

main.cs

Instead of directly using the true and false literals (values), we commonly use expressions:

cs

main.cs

The OR (||) operator returns true if any one of the operands is true:

cs

main.cs

Following is an example which uses the OR (||) operator:

cs

main.cs

The NOT (!) operator simply negates (inverts) the logical expression or logical value. So if an expression returns true, it changes it into false.

cs

main.cs

What is the expression (0 < 5 || 5 < 10) equal to?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 3. Розділ 2
some-alt