I. Value types and reference types
1. Difference between a value type and a reference type
(1) Value types store values directly, reference types are stored on worthy references
(2) value types are stored on the stack, and reference types are stored on the managed heap
2, if the variable is a reference, you can set its value to NULL, indicating that it does not reference any object
3. In C #, basic types such as bool and long are value types. Instead, most of the more complex C # data types, including the classes we declare ourselves, are reference types.
4. If you need to define your type as a value type, you should declare it as a struct.
Two. CTS type
The basic predefined types that C # recognizes are not built into the C # language, but are embedded within the. NET Framework.
Three. Pre-defined value types
1. Integral type
Name |
CTS Type |
Description |
Range |
SByte |
System.SByte |
8-bit signed integer |
-128~127 (-2 of 8-Time Square-7-1) |
Short |
System.Int16 |
16-bit signed integer |
-32768~32767 (-2 of 15-time Square-15-1) |
Int |
System.Int32 |
32-bit signed integer |
-2417483648~2147483647 (-2 of 31-Time Square-31-1) |
Long |
System.Int64 |
64-bit signed integer |
-9223372036854775808~9223372036854775807 (-2 of 63-time Square-63-1) |
Byte |
System.Byte |
8-bit unsigned integer |
0~255 (0~2 8-1) |
UShort |
System.UInt16 |
16-bit unsigned integer |
0~65535 (0~2 16-1) |
UInt |
System.UInt32 |
32-bit unsigned integer |
0-4294967295 (0~2 32-square-1) |
ULong |
System.UInt64 |
64-bit unsigned integer |
0~18446744073709551615 (0~2 64-1) |
Variables of all integer types can be assigned decimal or hexadecimal values, which require a 0x prefix.
1long x=0x12ab
2. Floating-point types
Name |
CTS Type |
Description |
Number of digits |
Range (approximate) |
Float |
System.Single |
32-bit single-precision floating-point number |
7 |
+-1.5 x 10 of 245 square ~+-3.4 x 10 38-Time Square |
Doble |
System.Double |
64-bit double-precision floating-point number |
15/16 |
+-5.0 x 10-324 Square ~+-1.7 x 10 308-Time Square |
3.decimal type
Name |
CTS Type |
Description |
Number of digits |
Range (approximate) |
Decimal |
System.Decimal |
128-bit high-precision decimal number notation |
28 |
+-1.0 x 10-28 Square ~+-7.9 x 10 28-Time Square |
4.bool type
Name |
CTS Type |
Description |
Number of digits |
Value |
bool |
System.Boolean |
Indicates true or FALSE |
NA |
Teue or False |
5. Character types
Name |
CTS Type |
Value |
Char |
System.Char |
Represents a 16-bit Unicode character |
The literal of a char type is enclosed in single quotation marks, such as ' A '. If you put the character in double quotes, the compiler will treat it as a string, resulting in an error.
Common escape characters
Escape sequences |
Character |
\‘ |
Single quotation marks |
\" |
Double quotes |
\\ |
Back slash |
/ |
Empty |
\a |
Warning |
\b |
Backspace |
\f |
Page change |
\ n |
Line break |
\ r |
Enter |
\ t |
Horizontal tab |
\v |
Vertical tab |
6 pre-defined reference types
Name |
CTS Type |
Description |
Object |
System.Object |
Root type, other types in the CTS are derived from it (including value types) |
String |
System.String |
Unicode string |
(ii) predefined data types