【发布时间】:2012-06-26 21:31:15
【问题描述】:
运营商description on MSDN有备注:
只有当 value 的值需要更多位时才会抛出异常 超出当前平台支持的范围。
虽然ToInt32's description 没有,所以我想标题并不完全正确(为简洁起见),
一个更正确的问题是:“为什么IntPtr.ToInt32 在 64 位模式下抛出 OverflowException 以获取 适合 Int32 而 Explicit(IntPtr to Int32) 不适合的值”
在反编译后的IntPtrToInt32和操作符看起来很相似:
public static explicit operator int(IntPtr value)
{
return (int) value.m_value;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public unsafe int ToInt32()
{
return (int) this.m_value;
}
不知道是什么让ToInt32抛出异常,是unsafe关键字吗?
【问题讨论】: