This documentation is archived and is not being maintained.

Compiler Error CS1643 

Error Message

Anonymous method of type 'type': not all code paths return a value

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;