|
一、MSDN描述
ValueType 类:提供值类型的基类
命名空间: System
程序集: mscorlib.dll
继承关系:System.Object
System.ValueType
派生类
值类型包括:字符、整数、浮点、布尔、枚举、结构(其实字符、整数、浮点、布尔是结构,下面会说明)
二、值类型花名册
1. 字符
Char 结构: 表示一个 Unicode 字符。
命名空间: System
程序集 : mscorlib.dll
在C# 中 char 是 System.Char 的别名
System.Char 继承 System.ValueType
常用属性和方法:
IsDigit(Char) 是否是数字
IsLetter(Char) 是否是字母
IsLetterOrDigit(Char) 是否是数字或字母
2. 整数
分为有符号整数和无符号整数
有符号整数 无符号
SByte <--> sbyte 8位 Byte <--> byte
Int16 <--> short 16位 UInt16 <--> ushort
Int32 <--> int 32位 UInt32 <--> uint
Int64 <--> long 64位 UInt64 <--> ulong
3. 浮点
单精度:Single <--> float
双精度:Double <--> double
4. 布尔 Boolean <--> bool
5. 枚举
Enum 类:为枚举提供基类
命名空间: System
程序集 : mscorlib.dll
原型定义:
[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class Enum : ValueType, IComparable, IFormattable, IConvertible
在C# 中 System.Enum 的别名为 enum
常见属性和方法:
Parse(Type, String) 解析枚举值
TryParse<TEnum>(String, TEnum)
6. 一些常见的结构 struct
a. Char、Int16、Int32、Int64、Single 、Double 以及无符号版本
b. IntPtr 结构:用于表示指针或句柄的平台特定类型
常用构造器:
IntPtr(Int32)
IntPtr(Int64)
var intPtr1 = new IntPtr(23222);
var intPtrZero = IntPtr.Zero; // 代表已初始化为零的指针或句柄
c. Guid 结构: 表示全局唯一标识符 (GUID)
常用构造器:
Guid(String)
常用属性和方法:
Guid.Empty Guid 类的只读实例,其值保证均为零
Guid.NewGuid() 产生一个新Guid
Guid.Parse
Guid.TryParse
ToString
d. DateTime结构 : 表示时间上的一刻,通常以日期和当天的时间表示
e. TimeSpan结构:表示一个时间间隔
f. Nullable<T> 结构:表示基础类型为值类型的对象,值类型与引用类型一样也可以分配 null |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|