Search code examples
c#warningssuppress-warnings

#pragma directive suppresses the warnings in the page it is specified or for the entire application?


I have one question:

when I use warning directive #pragma in one of the class file where I get the warning as "#pragma warning disable " then these specified warnings will be suppressed for entire application or only for that page?


Solution

  • It seems that the suppression is active until the end of file or until you restore the warnings.

    The right paragraph in the language specification is 9.5.8 that does not mention this fact. It can be inferred from section 9.5.1 where the specification talks about: conditional compilation symbols.

    See the following post for an exhaustive explanation:

    C#: Is pragma warning restore needed?