类型转换表

发生扩大转换。,当一个类型的值转换为相等或更大范围的另一种类型时。 收缩转换时,会发生一个类型的值转换为较小的另一种类型的值时。 本主题中的表阐释了两种转换类型显示的行为。
扩大转换

下表描述了可以执行,不会丢失信息的扩大转换。
类型可以转换,而不会丢失数据
ByteUInt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double, Decimal
SByteInt16, Int32, Int64, Single, Double, Decimal
Int16Int32, Int64, Single, Double, Decimal
UInt16UInt32, Int32, UInt64, Int64, Single, Double, Decimal
CharUInt16, UInt32, Int32, UInt64, Int64, Single, Double, Decimal
Int32Int64, Double, Decimal
UInt32Int64, UInt64, Double, Decimal
Int64Decimal
UInt64Decimal
SingleDouble
为 Single 或 Double 的那些扩大转换可能会导致丢失精度。 下表描述了有时会导致信息丢失的扩大转换。
类型可以转换
Int32Single
UInt32Single
Int64Single, Double
UInt64Single, Double
DecimalSingle, Double
收缩转换

为 Single 或 Double 的收缩转换可能导致信息丢失。 如果目标类型无法正确表达源的大小,则结果类型设置为常数 PositiveInfinity 或 NegativeInfinity。 ,当 Single 或 Double 的值超过 MaxValue 字段的值时,PositiveInfinity 由部件的正数由零和也会返回。 ,当 Single 或 Double 的值。 MinValue 字段中的值时,会NegativeInfinity 产生负数除以零时和也会返回。 从 Double 的转换到 Single 可能导致 PositiveInfinity 或 NegativeInfinity。收缩转换可能会导致其他数据类型的信息丢失。 但是, OverflowException 引发,如果将类型的值不在目标类型的 MaxValue 和 MinValue 字段指定的范围内,因此,转换在运行时检查确保目标类型的值不超过其 MaxValue 或 MinValue。 对 System.Convert 类的转换始终以这种方式检查。 下表列出了 OverflowException 使用 System.Convert 或所有签出的转换的转换,如果转换的类型的值不在结果类型的定义的大小。
类型可以转换
ByteSByte
SByteByte, UInt16, UInt32, UInt64
Int16Byte, SByte, UInt16
UInt16Byte, SByte, Int16
Int32Byte, SByte, Int16, UInt16, UInt32
UInt32Byte, SByte, Int16, UInt16, Int32
Int64Byte, SByte, Int16, UInt16, Int32, UInt32, UInt64
UInt64Byte, SByte, Int16, UInt16, Int32, UInt32, Int64
DecimalByte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64
SingleByte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64
DoubleByte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64

转载于:https://www.cnblogs.com/icestone10/archive/2013/01/31/3250570.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值