This documentation is archived and is not being maintained.

Compiler Error CS1612 

Error Message

Cannot modify the return value of 'expression' because it is not a variable

An attempt was made to modify a value type that was the result of an intermediate expression. Because the value is not persisted, the value will be unchanged.

To resolve this error, store the result of the expression in an intermediate value, or use a reference type for the intermediate expression.

Example

The following code generates error CS1612.

// CS1612.cs
public struct MyStruct
{
    public int Width;
}

public class ListView
{
    public MyStruct Size
    {
        get { return new MyStruct(); }
    }
}

public class MyClass
{
    public MyClass()
    {
        ListView lvi;
        lvi = new ListView();
        lvi.Size.Width = 33;  // CS1612
        // Use this instead:
        // MyStruct temp = lvi.Size;
        // temp.Width = 33;
    }

    public static void Main() {}
}
Show: