Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS1945
Collapse the table of content
Expand the table of content

Compiler Error CS1945

Visual Studio 2008

An expression tree may not contain an anonymous method expression.

Expression trees can only contain expressions. Anonymous methods can only represent statements.

To correct this error

  • Do not try to create an expression tree with a statement.

The following code generates CS1945:

// cs1945.cs
using System;
using System.Linq.Expressions;

public delegate void D();
class Test
    static void Main()
        Expression<Func<int, Func<int, bool>>> tree = (x => delegate(int i) { return true; }); // CS1945

Community Additions

© 2015 Microsoft