Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
The left-hand side of an assignment must be a variable, property or indexer
In an assignment statement, the value of the right-hand side is assigned to the left-hand side. The left-hand side must be a variable, property, or indexer.
To fix this error, make sure that all operators are on the right-hand side and that the left-hand side is a variable, property, or indexer. For more information, see Operators and expressions.
Example 1
The following sample generates 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() { }
}
Example 2
The following sample generates CS0131 when assigning to a constant field.
// CS0131b.cs
public class B
{
public static int Main()
{
const int j = 0;
j = 1; // CS0131
// try the following lines instead
// int j = 0;
// j = 1;
return j;
}
}
Example 3
This error can also occur if you attempt to perform arithmetic operations on the left hand side of an assignment operator, as in the following example.
// CS0131c.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;
}
}