C # statement,
What is a statement? A statement can be a single-line code ending with a semicolon, or a series of single-line statements in the statement block. Statement blocks are enclosed in brackets {} and can contain nested blocks.
1. Statement type
(1) Statement
Declaration statements mainly introduce new variables and constants. Variable declaration can be used to assign values to variables. A constant must be assigned a value. For example, int I; const int k = 10;
(2) expression statements
The expression statement used for calculation must be stored in the variable. For example, int result = 5*3;
(3) select statement
The selection statement executes different code segments based on one or more specified conditions. Mainly include if, if else, switch case
(4) iterative statements
Iterative statements are mainly used to traverse a set, or repeatedly execute a code segment until the specified conditions are met, mainly including do, for, foreach, in, while
(5) Jump statement
A jump statement redirects the executed statement to another code segment. Mainly include break, continue, default, goto, return, yield
(6) exception handling statement
It is used to handle errors during execution of a program, including throw, try-catch, try-finally, and try-catch-finally.
(7) Check and statement
The check and uncheck statements are used to specify whether to allow numeric operations to cause overflow when the result is stored in a variable but the variable is too small to accommodate the result value.
(8) await statement
Await statements are mainly used for thread exception handling.
(9) yield return Statement
The iterator defines the iteration of the set.
(10) fixed statement
Fixed statement prevents the garbage collector from relocating movable Variables
(11) lock statement
The lock statement is used to restrict only one thread to access a code block at a time.
(12) mark the statement
You can specify a tag for the statement and use the goto keyword to jump to the tag statement.
(13) empty statement
An empty statement contains only one semicolon. A null statement does not perform any operations. It can be used where a statement is required but no operation is required.