更新:2007 年 11 月
错误消息
无法修改“expression”的返回值,因为它不是变量
试图修改的值类型是中间表达式的结果。该值是不持久的,因此它将保持不变。
若要解决该错误,请将表达式的结果存储在中间值中,或对中间表达式使用引用类型。
示例
下面的代码生成错误 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() {}
}