Role of symbols in C # [memo]

Source: Internet
Author: User
~ Evaluate the population by bit;
! Non-logical operators;
% Remainder operator;
^ XOR operators;
& Bitwise operators;
| Or bitwise operator;
* It can be used as a multiplication symbol or a pointer;
+ Indicates the addition of mathematical operators;
= Indicates the value assignment operation;
\ Used to start the Escape Character. For example, \ n indicates line feed;
"Package string;
'Wrap a single character;
<Small logical operators;
> Large logical operators;
Used to separate parameters;
Indicates the object member selector or decimal point;
/Indicates the mathematical operator divided;

# Used for Conditional compilation or divisionCodeBlock.
For example: # If # else # define # region # endregion

? A single value type is commonly used to indicate null values, such as: Int? A = NULL;
It can also be used in combination with many characters to express different meanings.

?? This parameter is used in generics to specify the default value when the value type is null,
Int A = mynullable ?? 100;
// If mynullable is not empty, the value is assigned to a. Otherwise, 100 is assigned to.

++ Indicates auto-increment;
-- Indicates auto-subtraction;
& Indicates the logical relationship and;
| Indicates the logical relationship or;
= Indicates that the logical relationship is equal;
> = Indicates that the logical operator is greater than or equal;
<= Indicates that the logical operator is less than or equal;

<Indicates the Left shift operation;
> Indicates the right shift operation;
// Indicates a single line comment;

+ =,-=, * =,/=, % =, & = ,~ =, | =, Etc. It is the result of a mathematical operation between a number itself and a number. For example, a + = 10; complete form: A = a + 10;

<> It is widely used in generics and is used to enclose type parameters.

() Used in objects:
1. indicates the function parameter area;
2. Forced type conversion;
3. Set the computing priority;

{} Is used in the object:
1. indicates the code snippet scope;
2. Assist in some special operations in C # by specifying the function block, such as fixed and using;
3. In addition, in string formatting, the combination of {} and number indicates the position of the substring to be replaced in the target string, for example, String. format ("{0} + {1} = {3}", 1, 2, 3 );

[] This symbol is also common. It generally has three usage methods:
1. One is used to represent the index position in the array;
2. Use a feature of the add type;
3. Make up the index with the keyword this [...];

=> It is part of the Lamda expression, making the writing of anonymous functions more concise (later than 3.0 ). Usually it contains the expression parameter section, followed by the body section of the expression.

@ Symbol:
1. It is often used at the beginning of a string. It can tell the compiler to ignore escape characters;

2. When you name a variable or attribute, the variable name (or attribute name) conflicts with the keyword in. net. You can use "@ variable name" to bypass the restriction.
For example, int @ Int = 123;
// Here, when the @ int variable uses reflector to view the Il variable, int instead of @ int is displayed.

$ Symbol:
1. This symbol is used by the compiler in an anonymous method.
You can view the Il code to understand its name, but it is invisible to the C # code. The private method generated by the machine is not displayed in intelliisense and cannot be called explicitly.

2. debuggingProgramThis symbol can be used in code.
For example, when catch does not write the exception variable, for example: catch {...}
// To obtain exception information, enter $ exception in the "instant window" or "monitoring window.

? And: Symbol combination
Here? And: A Condition expression, such as: int c = A = B? A: B;

<% = And %> combination
Used to insert. Net code snippets into HTML code.
In Aspx. Net MVC, this character combination is very common, similar to the previous ASP, which is also one reason why some Programmers think MVC is returned to the ASP era.

<% @ And %> combination
Used to indicate the page instruction of aspx 2.0, which usually appears at the top of the page.
On the Aspx. NET page or user control, there are 11 commands (Note 1) in the format of <% @ [directive] [attribute = value] %>.

Note 1:

In ASP. NET, 11 pages or user control commands are as follows:

Assembly, control, implements, import, Master, mastertype, outputcache, page, previouspagetype, reference, register.

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.