The statement description on MSDN has a remark:
An exception is thrown only if the value value requires more bits than the current platform supports.
while ToInt32 description is wrong, I suppose the name is not entirely correct (for brevity),
a more correct question would be: "Why IntPtr.ToInt32 throws OverflowException in 64-bit mode for values ββthat fit in Int32 and Explicit (IntPtr in Int32), not"
In a decompiled IntPtr ToInt32 and the operator looks very similar:
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; }
I wonder what makes ToInt32 exception, is this an unsafe keyword?
source share