Assignment in .NET 3.5 expression trees

后端 未结 5 980
执笔经年
执笔经年 2020-12-16 01:39

Is it possible to encode an assignment into an expression tree?

5条回答
  •  离开以前
    2020-12-16 02:06

    No, I don't believe so.

    Certainly the C# compiler disallows it when converting a lambda expression:

    int x;
    Expression> foo = (x=y); // Assign to x and return value
    

    This yields the error:

    CS0832: An expression tree may not contain an assignment operator
    

提交回复
热议问题