43. My C # learning note 9

Source: Internet
Author: User
Tags character classes

Special operators:

is operator

The IS operator is used to check whether a variable is a specified type. If yes, returns true; otherwise, returns false.

For example: Create a console application to determine if the integer variable i is an integer type. The code is as follows:

int i=0;

BOOL Result= (i is int);

Console.WriteLine (result);

Console.ReadLine ();

Conditional operators

The conditional operator (?:) Returns one of two values based on the value of a Boolean expression. If the condition is true, the first expression is evaluated and the result of its calculation is the same, and if False, the second expression is evaluated and the result of its calculation prevail. Use format: Conditional? value 1: Value 2;

New operator

The new operator is used to create an instance of the type, which has the following 3 forms.

An object creation expression that is used to create an instance of a class type or value type.

An array-creation expression used to create an instance of an array type.

Represents the creation expression used to create a new instance of a representative type.

typeof operator

The typeof operator is used to obtain the type of the system prototype object, that is, the types object. The type class contains information about value types and reference types. The typeof operator can be used in various locations in the C # language to find information about reference types and value types.

For example: Create a console application, take advantage of the typeof operator to get information about an integral type, and output the result.

static void Main (string[] args)

{

Type mytype=typeof (int);

Console.WriteLine ("Type: {0}", MyType);

Console.ReadLine ();

}

Operator Precedence:

An expression in C # is a C # specification that is concatenated with operators, and the precedence of operators determines the order in which operations are performed in an expression. Operator precedence is equivalent to invoicing business processes, such as: Incoming, warehousing, sales, out of the library, can only follow this step to operate. The precedence of operators is also the same, which is calculated at a certain level, usually in order of precedence from highest to lowest:

Increment or decrement operation.

Arithmetic operations.

Relational operations.

Logical operations.

Assignment operation.

If the two operators have the same precedence, the expression on the left is processed first than the expression on the right. In an expression, you can adjust the operator's order of operations by (), placing the operators that want precedence operations in parentheses (). When the program starts executing, the operators within the parentheses () are executed preferentially.

The char class is primarily used to store a single character. Use only 16 for (two bytes) of memory space. When defining a character variable, enclose it in single quotation marks, such as ' s ' for a character. and "s" represents a string. Although it is only a character, it still represents a string, not a character, because of the use of double quotation marks.

The Char definition is very simple and can be defined by the following code.

Char ch1= ' 1 ';

Char ch2= ' 2 ';

Char defines only one Unicode character, which is a generic character encoding for the current computer, and it sets a uniform binary encoding for each character in different languages. Used to meet the requirements of cross-language, cross-platform text conversion, processing.

Use code for static methods of some character classes:

Char a = ' a ';

is not the letter

Char.isletter (a);

is not the number

Char.isdigit (a);

is not a letter or a number

Char.isletterordigit (a);

is a lowercase letter

Char.islower (a);

Is it a capital letter?

Char.isupper (a);

Is it punctuation?

Char.ispunctuation (a);

is not a separator

Char.isseparator (a);

is not blank

Char.iswhitespace (a);


Escape characters:

An escape character is a special character variable that begins with a backslash "\" followed by one or more characters. The escape character has a specific meaning, which differs from the original meaning of the character, so it is called "escaped". For example, a character is defined, and the character is a single quotation mark, and an error is generated if the escape character is not used.

The escape character is equivalent to a power converter, the power converter is a means to obtain the required form of power supply, for example: AC into DC, high voltage into low voltage, low frequency to high frequency. An escape character is also a combination of characters that convert a character to another form of operation or that cannot be used together.

The escape character \ only operates on a single character immediately following it.

The commonly used escape characters are:

\ nthe carriage return to newline.

\ t Horizontal tabulation

\ " double quotation marks

\ ' single quotation mark

\ \ Backslash

\b backspace

\ r Enter

\f Page Change

This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1977722

43. My C # learning note 9

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.