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

StackOverflow https://stackoverflow.com/questions/18911906

  •  29-06-2022
  •  | 
  •  

Domanda

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?

È stato utile?

Soluzione 2

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?

Altri suggerimenti

The pre-processor directives are applied only to the compilation unit where they are defined, in that case it is the class file where you used them

If you use the #pragma warning disable it is enabled until the end of the file.'

I quote from the language specification (9.5.1):

The symbol remains defined until a #undef directive for that same symbol is processed, or until the end of the source file is reached.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top