Compiler Error CS1643
Not all code paths return a value in method of type 'type!'
This error occurs if a delegate body does not have a return statement, or has a return statement that the compiler is unable to verify will be reached. In the example below, the compiler does not attempt to predict the result of the branching condition in order to verify that the anonymous method block always returns a value.
Example
The following sample generates CS1643:
// CS1643.cs
delegate int MyDelegate();
class C
{
static void Main()
{
MyDelegate d = delegate
{ // CS1643
int i = 0;
if (i == 0)
return 1;
};
}
}
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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for