Compiler Error CS0832

Visual Studio 2008

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.

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;

Community Additions