Not a member?     Existing members login below:
Holidays Offer
 

Fundamentals of Computer Programming with C#


Chapter 5. Conditional
Statements
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
switch-case.
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
statements.
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:
Operator
Action
== 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:
 
 
 
Remove