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
arithmetic_expression relational_operator arithmetic_express
After 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
About This Book
Introduction of C# (C Sharp)
Data Type and Variables
►Logical Expressions and Conditional Statements
"if" Statements - Example
"switch" Statements - Example
Arrays and Loop Statements
Data Type Features
Floating-Point Data Types
Passing Parameters to Methods
Execution Environment Class
Visual C# 2010 Express Edition
C# Compiler and Intermediate Language
Compiling C# Source Code Files
MSBuild - Microsoft Build Engine
Memory Usages of Processes
Multithreading in C#
Async Feature from C# 5
WPF - Windows Presentation Foundation
Partial Classes and Partial Methods
PDF Printing Version