C # basic knowledge

Source: Internet
Author: User

1 : JIT (Instant compilation ). When a method is called for the first time JIT Will change the method Il CodeConvert CPU Command. When you call this method again, you only need to execute the corresponding command. The first call process of a method is roughly as follows: 1 Obtain Method Il Code; 2 : Allocate memory; 3 : Set Il Code Conversion CPU Command exists 2 Memory allocated; 4 : Point the pointer to the method in the method table 2 Allocated memory; 5 : Jump 2 The allocated memory executes the commands, that is, CPU Command.

 

2:AsHigher performanceIs.IsIs used to determine whether the current type is compatible with the target type, that is, whether it is the same type or whether the target type is the parent type of the current type. To force type conversion, you must also determine the type compatibility. If it is not compatible, a type conversion exception is thrown. If your code type conversion usesIs +Forced type conversion makes two compatibility judgments, andAsOnly one type conversion is allowed.

 

3 : C # int corresponding FCL int32 , long corresponds to int64 in FCL, same type, 64 bit CPU the storage space is 32 bit CPU 2 times.

 

4:StringIs the reference type. constant strings exist in the string pool. If a string appears multiple times in the Code, these are references to the string pool,String S = "A" + "B ";Memory is allocated only once, and the compiler will directly compile itString S = "AB"; sIs for the string poolAB.

 

5: Concatenation of a large number of stringsStringbuilder, A small amount is added with strings, can be used+ =Better,String. FormatThe efficiency is low, and its memory is actuallyParams object [] + stringbuilder,ParamsIt is also inefficient. To add strings or retrieve some of them, it is necessary to re-allocate the memory and then store the corresponding strings.FCLMost of the code is usedC #Write, while the operation string is written using unmanaged code, in consideration of performance.

 

6: Don't seeNewIt is assumed that the memory will be allocated in the hosting heap. Value-type variables are allocated on the thread stack. Although the struct can be usedNewBut the compiler determines that it is a value type and will be processed according to the value type. Of courseIlNo in the codeNewobjCommand.

 

7: Static classes are compiledSealed AbstractType, so he cannot be inherited or instantiated, so his attributes and Methods belong to the type, and they do not belong to the object, and must be inherited directly.Object.

 

8 : Const And Readonly , Il What is stored in the Code is Const Variable value instead of reference, so modification is impossible. DLL Only references the other DLL One Const Variable, then this DLL It will not be referenced, because the value of the variable is known during compilation, so the memory will not be allocated during running, Readonly It indicates that you cannot modify its direction, but you can modify the value of the variable it points.

 

9: Generic,C #Generic andC ++The template difference is that the reference type,C ++The template generates a new type for each type (the reference type is not), andC #In generics, the reference type uses the same type, and only the value type uses different types. Because reference is a pointer reference, and the space required for value type storage is different. In C ++, the template is half-exclusive and T is half-exclusive to void *, so that the pointer type does not need to generate a set of code.

 

For other basic knowledge, please read this blog: Technical microblog written these days

Author: Chen taihan

blog: http://www.cnblogs.com/hlxs/

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.