Fundamentals of Computer Programming with C# HTML version

Chapter 5. Conditional
In This Chapter
In this chapter we will cover the conditional statements in C#, which we
can use to execute different actions depending on a given condition. We will
explain the syntax of the conditional operators if and if-else with suitable
examples and explain the practical application of the operator for selection
We will focus on the best practices to be followed in order to achieve a
better programming style when using nested or other types of conditional
Comparison Operators and Boolean Expressions
In the following section we will recall the basic comparison operators in the
C# language. They are important, because we use them to describe
conditions in our conditional statements.
Comparison Operators
There are several comparisons operators in C#, which are used to compare
pairs of integers, floating-point numbers, characters, strings and other types:
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Comparison operators can be used to compare expressions such as two
numbers, two numerical expressions, or a number and a variable. The result
of the comparison is a Boolean value (true or false).
Let’s look at an example of using comparisons: