Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 4) CS0429

Unreachable expression code detected

This error occurs whenever part of an expression in your code is unreachable. In the following example, the condition false && myTest() meets this criteria because the myTest() method will never get evaluated due to the fact that the left side of the && operation is always false. As soon as the && operator evaluates the false statement as false, it stops the evaluation, and will never evaluate the right side.

The following code generates CS0429.

// CS0429.cs
public class cs0429 
{
    public static void Main() 
    {
        if (false && myTest())  // CS0429
        // Try the following line instead:
        // if (true && myTest())
        {
        }
        else
        {
            int i = 0;
            i++;
        }
    }

    static bool myTest() { return true; }
}
Show:
© 2014 Microsoft