Home > Backend Development > C#.Net Tutorial > What different types of conditional statements does C# support?

What different types of conditional statements does C# support?

WBOY
Release: 2023-09-16 08:49:02
forward
706 people have browsed it

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;
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template