This topic has not yet been rated - Rate this topic

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.

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;
        };
    }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ