Is there a way to get VS2008 to stop warning me about unreachable code?

前端 未结 8 1929
我在风中等你
我在风中等你 2021-02-05 02:04

I have a few config options in my application along the lines of

const bool ExecuteThis=true;
const bool ExecuteThat=false;

and then code that

8条回答
  •  不思量自难忘°
    2021-02-05 02:12

    To disable:

    #pragma warning disable 0162
    

    To restore:

    #pragma warning restore 0162
    

    For more on #pragma warning, see MSDN.

    Please note that the C# compiler is optimized enough to not emit unreachable code. This is called dead code elimination and it is one of the few optimizations that the C# compiler performs.

    And you shouldn't willy-nilly disable the warnings. The warnings are a symptom of a problem. Please see this answer.

提交回复
热议问题