开发者

Visual Studio 2008 C# compiler const if statement problem!

When the following code in put in Visual Studio 2008 C#, The word "System" is underlined and is marked as "unreachable code":

public static class Program
{
    const int motors = 1;
    static void Main(string[] args)
    {
        if (motors 开发者_运维问答< 1)
        {
            return;
        }
        System.Console.WriteLine("program run.");
    }
}

This is obviously incorrect, and I'm wondering if anyone can explain the behaviour. Thanks!

[edit] I'm using VS 2008 Professional.


Try doing a clean and build. I suspect there is a glitch somewhere as it is the return; line that is unreachable.

I just tried this in 2008 and it is the return line that I am warned about.


There are no problems with your code. Could be that a previous error already corrected produced the underline, in that case Visual Studio did not update the UI correctly. That has happened to me very often, my advise is (re)build the project and check if the underline has gone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜