Export (0) Print
Expand All
Expand Minimize

Compiler Error CS1731

Visual Studio 2008

Cannot convert 'expression' to delegate because some of the return types in the block are not implicitly convertible to the delegate return type.

This error is generated when a lambda expression or anonymous method has a return type that is not compatible with the delegate's return type.

To correct this error

  • Change the return type of either the delegate or the expression.

The following code generates CS1731:

class CS1731
{
    delegate double D();
    D d = () => { return "Who knows the real sword of Gryffindor?"; };
}

Community Additions

ADD
Show:
© 2014 Microsoft