Search C # (statement one) a week

zhaozj2021-02-16  64

Search C # (statement one) a week

C # Talent Bird (QQ: 249178521)

Statement

· Statement

W declaration statement

w expression statement

· Piece

W is a unknown collection of the statement

W included between {}

Declare statement; // must have a different number

Expression statement; // must have a distinction

{

Statement;

Statement;

...

} // No need to have a separate number

C # and C , Java, you can use the statement statement as a normal statement. In other words, you can use a statement statement anywhere without having to start at the beginning of the program.

A block defines a range. Any variable declared in the block disappeared at the end of the block.

2. THROW statement

· Throw statement throws an error

w Check it very useful when checking the previously defined conditions.

The type of W expressions must be system.exception or its derived class.

String Daysuffix (int days)

{

IF (Days <0 || Days> 31)

{

Throw new

ArgumentOutofRangeException ("days");

}

...

}

3.Return statement

· Return statement returns a value

W Expression must match the type of return value

W is best a function has only one Retun statement

w Use Return; end a VOID function

String Daysuffix (int days)

{

String result;

...

Return Result;

}

A function can return a single value via a return statement. The type of expression in the RETURN statement must be the same as that of the return value of the function declaration or can be implicitly converted to the type of return value.

If you have to return multiple values ​​from a function, you can use the following methods:

ü You can put the return value in a structure

ü You can put the return value in an array or a collection class.

ü You can use OUT type parameters in a function

4.bool

· BOOL is a keyword

W It is the alias of System.Boolean

W It can only be True and False

BOOL love = true;

Bool teeth = false;

//correct

System.Boolean Love = true;

System.Boolean Teeth = FALSE;

//correct

Using system;

...

Boolean Love = True;

Boolean Teeth = FALSE;

//correct

Boolean Love = True;

Boolean Teeth = FALSE;

// Error, because there is no system namespace, please pay attention to the case

转载请注明原文地址:https://www.9cbs.com/read-22163.html

New Post(0)