C # is a type-safe development language in which the data types are divided into value types (value type) and reference types (Reference type).
One, value types (value type)
- Character: Char u+0000-u+ffff 16-bit Unicode character (in fact, the character is also an integral type)
- Integral type: sbyte, Byte, short, ushort, int, uint, long, ulong
- Float type: Float (7-bit valid), double (15 to 16-bit significant bit)
- The decimal:128 bit data type, which has a higher precision (28 to 29 bit significant bits) and a smaller range than floating-point types, is suitable for financial and currency calculations.
- Boolean: bool (TRUE or FALSE, true or false)
- Structure: struct
- Enum: enum
Value Type Summary:
- characters, integers, floats, decimal, and bool are all instances of struct types, and the values of these types are given by const constants MaxValue and MinValue within these types of structures.
- The struct (see * superscript) for the value types of character, integer, float, decimal, and bool are listed:
- Enum type is an enum Abstruct class type.
- Value types are implicitly derived from child System.ValueType.
- Enum and struct definitions should be at the same class or within the class but not inside the method.
struct-body ************************************************ for value types
Char Char
SByte sbyte
BYTE byte
Short Int16
UShort UInt16
int Int32
UINT UInt32
Long Int64
ULONG UInt64
Float single
Double Double
Decimal decimal
BOOL Boolean
*************************************************************************************************************** **
Second, reference type (Reference type, variable of reference type is also called object)
- Class: Classes
- Interface: interface
- Delegate: Delegate
- Object:. NET built-in reference types
- String:. NET built-in reference types
Summary of reference types:
Class: Is an abstraction of an object with the same characteristics
Interface: Uniform constraint rules for seamless sharing of data and communication between objects of a homogeneous nature
Delegate: Similar to a pointer in C + +, the method name can be passed as a parameter, unlike a delegate that is type-safe.
Object:. The base class for all classes in net
String: A sequence of strings (0 or more Unicode characters)
Iii. comparison of value types and reference types
- Value types allocate storage space on the stack of memory, whereas reference types allocate storage on the heap of memory
- When a value type is assigned a copy is worth a copy, and the reference type assignment only saves the address of the applied object (. NET called "References")
- Value types allocate memory space faster than the application type allocates memory space, but duplicate value type assignments can cause excessive memory overhead and require a reasonable trade-off in memory overhead.
- Value types cannot contain null, and reference types can be null
- ......
. NET value types and reference types