This documentation is archived and is not being maintained.

Compiler Error CS0445 

Error Message

Cannot modify the result of an unboxing conversion

The result of an unboxing conversion is a temporary variable, and the compiler prevents you from modifying such variables because any modification would go away when the temporary goes away. To fix this, use a value type to store the intermediate expression. You will then be able to assign a value to the value type.

The following code generates CS0455:

// CS0445.CS
public struct Point 
{
    public int x;
    public static void SetX(object obj, int x) 
    {
        ((Point)obj).x = x; // CS0445
    }
}
class UnboxingTest{public static void Main(){}}


Show: