Compiler Warning (level 4) CS0429

 

Updated: July 20, 2015

System_CAPS_ICON_note.jpg Note

For the latest documentation on C#, visit the C# Guide on docs.microsoft.com.

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: