几种类型所占的空间大小
| 类型 | 空间占用(字节) |
| byte | 1 |
| short | 2 |
| int | 4 |
| long | 8 |
| char | 2 |
| float | 4 |
| double | 8 |
| decimal | 16 |
| bool | 1 |
一个字节等于8比特(1byte=8bit).
注意:在C# 中 bool类型不能转换为int类型
存储在类型中的信息包括
-
The storage space that a variable of the type requires.(类型变量所需的存储空间)
-
The maximum and minimum values that it can represent.(它能表示的最大值和最小值)
-
The members (methods, fields, events, and so on) that it contains.(它包含的成员(方法、字段、事件等))
-
The base type it inherits from.(它继承的基本类型)
-
The location where the memory for variables will be allocated at run time.(运行时将分配的变量的位置)
-
The kinds of operations that are permitted.(运行的操作种类)
静态成员始终按类名(而不是实例名称)进行访问。
隐式转换不需要特殊语法,因为转换是类型安全的,并且不会丢失任何数据。
参考链接: