[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