Conditional Statements in C sharp

Conditional Statements is a block that execute based on a condition and they are divided into two categories

  1. Conditional Branching;
  2. Conditional Loop;
1. Conditional Branching :- These statements allows us to branch the code depending on which certain condition were meet or not . C# has 2 constructors for branching code ; the; if statement which allows us to test whether a specific condition is meet, and the switch statement which allows us to compare an expression with a number of different values.

Syntax declaration for if statement;

If Syntax

Example 

Syntax for Switch Statement


Note : -  In C# language using a break statements after each and every case block is mandatory. Whereas it is optional in C and C++ languages. But in C# even after default we need to use break.

Example 


No comments:

Post a Comment