C # Learning Note Day three
Chapter 3 Types
3.3 Reference Types
A variable of a reference type is also an object, with six types:
(1) Object Type
(2) String type
(3) class type
(4) Array type
(5) interface type
(6) Delegate type
Before you use a variable of a reference type, you first determine whether the value of the variable is null. If it does, it can't be accessed directly .
1. Class type: Support inheritance mechanism
2. Object type: Built-in reference type , i.e. System.Object
3. String type : a sequence of 0 or more Unicode characters, corresponding to System.String, created using double quotation marks , Once it is created, the contents of the created memory cannot be modified, and the value can only be reassigned to a new memory.
4. Array type : When declaring an array, the element type is followed by the brackets
5. Interface type: An interface is simply a data structure that can declare a member of a database and a function, which can only sound properties, methods, and events, but cannot implement these properties, methods, and events
6. Delegate type: It can refer to one or more methods, be able to pass the method as a parameter, and can also define the callback method
3.4 packing and unpacking
Effect: Conversion of values of value types and reference types to each other
The reference type is always allocated on the managed heap, and the value type is allocated on the stack
1. Boxing: Converts a value type to a reference type by assigning an object instance first, then copying the value of the value type to the instance, and sharing the same instance before and after boxing for the reference instance
Four common types of boxing:
(1) value type to Object type
(2) value type to System.ValueType type
(3) Type of interface to which value types are implemented
(4) enum type to system.enum type
2. Unpacking: Converting a reference type to a value type, the procedure is to check whether the object instance is a boxed value of the given value type, and copy the value from the instance ( Check that step more than boxing )
Four Common unpacking types:
is to turn the boxing process in front
C # Learning Note day_three