[C # advanced series] 05 primitive type, reference type, and Value Type,

Source: Internet
Author: User

[C # advanced series] 05 primitive type, reference type, and Value Type,

Primitive type and FCL type

FCL refers to Int32, which is supported by CLR.

The primitive type refers to the int type, which is supported by the C # compiler. In fact, it will still be converted to the Int32 type after compilation.

Those who have learned C will surely remember that int may have different bytes on 32-bit machines and 64-bit machines, but in C #. NET, int represents Int32.

Because there is a one-to-one ing between the primitive type and the FCL type. In addition, note that the dynamic actually corresponds to an Object, but the C # compiler allows a simple syntax to involve dynamic variables in dynamic scheduling.

The expression is composed of letters. The compiler can evaluate the expression at compilation.

Boolean found = false; // The generated code sets found to 0Int32 x = 100 + 20 + 3; // x to 123 String a = "a" + "bc "; // set s to "abc"

Checked and unchecked primitive type operations

This command is used to check overflow and not overflow. The default value is unchecked, but this can be changed. If you check for overflow, an exception is reported. If you do not check for overflow, roll back.

Reference Type and Value Type

For example, Int32 and DayOfWeek are both of the struct and enum types, while the struct type is actually derived from System. valueType type, while Enum type is derived from System. enum type. The Enum type is ultimately derived from the System. ValueType type.

Well, there are quite a few differences between the two, but basically this is the most basic, and basically it is a book, so I am too lazy to write.

Packing and unpacking

Packing is to create a memory space in the heap for the value type originally in the stack, copy the value type data, and add type pointers and synchronized block indexes for all reference types, then return the reference address of the memory space.

In turn, unboxing obtains the address of each field in the packing object, and then copies the values contained in these fields from the heap to the stack.

From the above we can see that packing and unpacking actually affect efficiency, so we should avoid it when writing code.

-- To be continued

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.