以下是C#主要数据类型的分类图示,采用层次结构展示:
C#数据类型
├── 值类型 (Value Types)
│ ├── 简单类型 (Simple Types)
│ │ ├── 整数类型
│ │ │ ├── sbyte (-128~127)
│ │ │ ├── byte (0~255)
│ │ │ ├── short (-32768~32767)
│ │ │ ├── ushort (0~65535)
│ │ │ ├── int (-2147483648~2147483647)
│ │ │ ├── uint (0~4294967295)
│ │ │ ├── long (±9223372036854775808)
│ │ │ └── ulong (0~18446744073709551615)
│ │ ├── 浮点类型
│ │ │ ├── float (±1.5E-45~3.4E38, 7位精度)
│ │ │ └── double (±5.0E-324~1.7E308, 15位精度)
│ │ ├── 高精度小数
│ │ │ └── decimal (±1.0E-28~7.9E28, 28位精度)
│ │ └── 布尔类型
│ │ └── bool (true/false)
│ ├── 字符类型
│ │ └── char (Unicode字符)
│ ├── 结构类型 (struct)
│ └── 枚举类型 (enum)
│
└── 引用类型 (Reference Types)
├── 类类型 (class)
│ ├── object (所有类型基类)
│ ├── string (Unicode字符串)
│ └── 用户自定义类
├── 接口类型 (interface)
├── 数组类型 (array)
└── 委托类型 (delegate)
特殊类型:
├── 可空类型 (Nullable<T>)
├── 指针类型 (unsafe上下文)
└── 动态类型 (dynamic)
关键特征说明:
-
值类型:
-
引用类型:
-
类型转换关系:
graph LR
byte-->short-->int-->long-->float-->double-->decimal
char-->int
-
内存占用对比:
- bool: 1字节
- DateTime: 8字节
- Guid: 16字节
- string: 20+(n*2)字节(n=字符数)
注意:实际内存占用可能因运行时环境和平台而异。值类型在作为类的成员时可能存储在堆上。
|