Home  >  Article  >  Backend Development  >  What different types of conditional statements does C# support?

What different types of conditional statements does C# support?

WBOY
WBOYforward
2023-09-16 08:49:02645browse

C# 支持哪些不同类型的条件语句?

Conditional statements require the programmer to specify one or more conditions to be evaluated or tested by the program, and one or more statements to be executed when the conditions determine to be true. Optionally, Execute other statements when the condition determines to be false.

The following are the types of conditional statements:

Serial number Statement and description
1 if statement

The if statement consists of a Boolean expression followed by one or more statements.

2 if...else statement

The if statement can be followed by an optional The selected else statement is executed when the Boolean expression is false.

3 Nested if statements

You can add another if or else if An if or else if statement is used inside the statement.

4 #switch statement

The switch statement allows variables to be tested for equality and Compares to a range of values.

5 Nested switch statement

You can use it inside another switch statement A switch statement.

Let’s look at an example of nested switch statements in C#:

switch (a) {
   case 100:
   Console.WriteLine("This is part of outer switch ");

   switch (b) {
      case 200:
      Console.WriteLine("This is part of inner switch ");
      break;
   }
   break;
}

The above is the detailed content of What different types of conditional statements does C# support?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:BitArray class in C#Next article:BitArray class in C#