C # statement,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.