Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
An expression tree may not contain an assignment operator.
An expression tree does not preserve variable state or have any concept of a storage location.
To correct this error
- Remove the assignment operator from the lambda or query expression.
Example
In the example code, as in all lambda expressions, x is just an input parameter being passed by value. Its value cannot be changed in an expression tree. It can be changed in a delegate lambda.
// cs0843.cs
using System;
using System.Linq;
using System.Linq.Expressions;
public class C
{
public static int Main()
{
Expression<Func<int, int>> e = x => x += 5; // CS0843
return 1;
}
}