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.
- 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?"; };
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: