Basic knowledge of C # four

Source: Internet
Author: User

Basic knowledge of C # four

Written by Zhu Zhu, please specify from Zhu Zhu Homeland http://blog.csdn.net/zhgl7688

1. The conditional operator is the ternary operator (?:): It has a test expression and two result expressions, the test is true, the first result expression is returned, or the second result expression is returned.

2. User-defined type conversions are divided into: implicit conversions and explicit conversions, which are compiled automatically, which perform conversions only when the display conversion operator is used.

3, implicit conversion: with publicstatic implicit operator, explicit conversion with explicit replace implicit. Example http://blog.csdn.net/zhgl7688/article/details/42090383

4. A class cannot write explicit and implicit declarations at the same time, only one of them, but if an implicit conversion is declared, its corresponding display transformation is also provided automatically. If an explicit conversion is declared, its corresponding implicit conversion does not provide this file.

5, operator overloading can only be used for classes and structs, declared with the operator keyword, at least one of the parameters must be class or struct type; declared as public static. Example: public static type operator operator (parameter class/struct, ...) {//...}.

6, not all operators can be overloaded. Overloaded types cannot do: Create new operators, change the syntax of operators, redefine how operators handle predefined types, change the precedence or binding of operators.

7. The typeof operator returns any type of System.Type object as its argument. Type T=type (SomeClass). The typeof operator cannot be overloaded.

8, the type of statement: Declaration statement, embedded statement, label statement.

9. Control Flow statement: Conditional statement (if, if...else, switch), loop statement (while, do, for, foreach), jump statement (break, continue, return, Goto, throw);

10. After the case in the switch statement, the expression must be a constant expression and must be fully evaluated at compile time, and must be the same as the test expression type. It must be followed by a break or goto statement unless an executable statement is inserted between the two branch labels.

11. Do...while (test expression): A semicolon is required after the closing parenthesis of the test expression.

12. For loop: Some parts of the statement are optional, but semicolons are required. Initialization statements and iterator representations can contain multiple expressions, as long as they are separated by commas.

13. The break statement is used to: for, foreach, while, do. Used to execute a statement that jumps out of the inner envelope.

14. Continue statements are used to: while, do, for, foreach. Used to execute the statement that goes to the next loop.

15. Label statement: An identifier followed by a colon and followed by a statement. Only allowed inside the block.

16, Tags: have their own declaration space, but not within the overlapping range with another label identifier, nor can it be a keyword.

17. The scope of the label statement: The block in which the declaration resides, and any block nested inside the block.

18, goto statement: Unconditionally go to the label statement. It can also be used inside a switch statement to control the transfer of the corresponding named Branch label inside.

19. The using statement differs from the using reference, helping to simplify the process and ensure that resources are handled appropriately. ‘

20. Using statements can be used for multiple resources of the same type, and resource declarations are separated by commas. The using can be nested.

Style: Using (Resoucetype id1=expr1,id2=expr2,....) Embededstatement

This document was written by Zhu Zhu, reproduced please indicate from Zhu Zhu Homeland http://blog.csdn.net/zhgl7688

Basic knowledge of C # four

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.