<?xml version="1.0"?>
<clause number="11.3.2" title="Unboxing conversions">
  <paragraph>An unboxing conversion permits an explicit conversion from type object to any <non_terminal where="11.1">value-type</non_terminal> or from any <non_terminal where="11.2">interface-type</non_terminal> to any <non_terminal where="11.1">value-type</non_terminal> that implements the <non_terminal where="11.2">interface-type</non_terminal>. An unboxing operation consists of first checking that the object instance is a boxed value of the given <non_terminal where="11.1">value-type</non_terminal>, and then copying the value out of the instance. </paragraph>
  <paragraph>Referring to the imaginary boxing class described in the previous section, an unboxing conversion of an object box to a <non_terminal where="11.1">value-type</non_terminal> T consists of executing the expression ((T_Box)box).value. <example>[Example: Thus, the statements <code_example><![CDATA[
object box = 123;  
int i = (int)box;  
]]></code_example>conceptually correspond to <code_example><![CDATA[
object box = new int_Box(123);  
int i = ((int_Box)box).value;  
]]></code_example>end example]</example> </paragraph>
  <paragraph>For an unboxing conversion to a given <non_terminal where="11.1">value-type</non_terminal> to succeed at run-time, the value of the source operand must be a reference to an object that was previously created by boxing a value of that <non_terminal where="11.1">value-type</non_terminal>. If the source operand is null or a reference to an incompatible object, a System.InvalidCastException is thrown. <table_line/>
</paragraph>
</clause>
