**C# Tutorials - Herong's Tutorial Examples** - Version 3.30, by Dr. Herong Yang

Logical Expressions

This section describes logical expressions - expressions resulting a Boolean value with comparison operations and logical operations.

**Logical expression** is a way of expressing a logical condition, upon which certain parts
of the program execution flow can be altered. For example, a furniture store wants the
following delivery charges in its invoice program: if the total amount of an order is
less than $200.00, delivery is charged as $25.00; if the amount is greater than or
equal to $200.00, delivery is free. Here "amount is less than $200.00" is a logical condition
that needs to be entered in C# program as a logical express.

The most simplest logical conditions involves **relational operators**:

- ">": Greater than
- "<": Less than
- ">=": Greater than or equal
- "<=": Less than or equal
- "==": Equal
- "!=": Not equal

A relational operation can be entered into C# programs as a logical expression with the following syntax:

logical_expression: arithmetic_expression relational_operator arithmetic_expressAfter evaluation, a logical expression will produce a boolean value, true or false.

Examples of logical expressions are:

- "1 < 2": This is a simple logical expression. The resulting value is true.
- "1 > 2": This is also a simple logical expression. The resulting value is false.
- "quantity * price < 200.00": The arithmetic expression "quantity * price" will be evaluated first. Its result will be then compared with 200.00. The resulting value is true or false, depending on the resulting value of arithmetic expression.
- "exam_score == 100": If the value in exam_score is equal to 100, the resulting value will be true. Otherwise, it will be false.

*Last update: 2010.*

Table of Contents

►Logical Expressions and Conditional Statements

Visual C# 2010 Express Edition

C# Compiler and Intermediate Language

Compiling C# Source Code Files

MSBuild - Microsoft Build Engine

System.Diagnostics.FileVersionInfo Class

WPF - Windows Presentation Foundation