更新:2007 年 11 月
错误消息
赋值号左边必须是变量、属性或索引器
在赋值语句中,右边的值赋给左边。左边必须是变量、属性或索引器。
若要修复此错误,请确保所有运算符都位于右边,而左边是变量、属性或索引器。有关更多信息,请参见语句、表达式和运算符(C# 编程指南)。
示例
下面的示例生成 CS0131。
// CS0131.cs
public class MyClass
{
public int i = 0;
public void MyMethod()
{
i++ = 1; // CS0131
// try the following line instead
// i = 1;
}
public static void Main() { }
}
如果您试图对赋值运算符的左边执行算术运算(如下面的示例中所示),也可能发生此错误。
// CS0131b.cs
public class C
{
public static int Main()
{
int a = 1, b = 2, c = 3;
if (a + b = c) // CS0131
// try this instead
// if (a + b == c)
return 0;
return 1;
}
}