C# Decision Making

C# Decision Making is used to requires the programmer to specify any one or more conditions to be evaluated by the program. In decision making, a certain block of code needs to be executed when given condition is fulfilled. It execute a statement or set of statements. If the given condition is determined to be true, other statements will be executed if the given condition is determined to be false.

Given below is the structure of decision making in C# programing languages:
C# Decision Making

Types of Decision Making in C#:

Statement Description
if statement It consists of a boolean expression followed
by one or more statements.
nested if statementsIt is used in one if or else if statement inside
another if or else if statement(s).
if…else statementIt can be followed by an optional else statement,
which executes when the boolean expression is false.
switch statementIt allows a variable to be tested for equality against a list of values.
nested-switch statementsIt can use one switch statement inside another switch statement(s).

These types are explained in the next sections.


?operator

In the previous chapter, we have covered the conditional operator, ?:which can be used to replace if...elsestatements. It has the following general form:

Exp1 ? Exp2 : Exp3;

Where Exp1Exp2and Exp3are expressions. Please pay attention to the use and position of the colon.

1. the Exp1expression is evaluated and evaluated. If the evaluation result is true, it Exp2is evaluated and returned as the entire value. If the Exp1evaluation result is false ( false), the Exp3expression is evaluated, and its value is returned as the value of the expression.

int a = 1;
int b = 2;
int c = 0;
c = (a>b)? a: b;