Evaluation of C# constant expression by VS.NET 2010

Viewed 360

When I tried a sample expression in C# in Visual Studio

public int Test()
{
    if (10/2 == 5)
        throw new Exception();
    return 0;
}

When I keep the expression 10/2 == 5, the vs.net automatically throws a warning "Unreachable Code Detected".

If I change the expression 10/2 == 6, the IDE is happy? How does it happen?

Edited: Sorry for the incomplete question. It happens so instantly and happens even before compiling the code?

I have upvoted each of the replies and accepted the first answer on FIFO basis

7 Answers
Related