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.
Example
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; }
}
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