Edit

Share via


Compiler Error CS1731

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

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

Example

The following code generates CS1731:

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