What is #pragma c # [duplicate]

5

While maintaining a code in a web service I came across the following code snippet:

#pragma warning disable 1591

When searching for its meaning, I did not find anything in Portuguese that was easily accessible.

Question

What is #pragma ? And when should it be used?

    
asked by anonymous 06.06.2017 / 19:34

2 answers

3

The #pragma is used to pass specific instructions to the compiler

To use, you must enter #pragma nome-configuracao argumentos

In the following example the warnings for the test code snippet are disabled, you may notice that there is a variable that is declared and not used, this would of course display a warning in the compilation, but since we disable it,

#pragma warning disable warning-list  
public void teste(){
    string naoUtiliza = "Teste";
    return "Teste";
}
#pragma warning restore warning-list  
    
06.06.2017 / 19:40
3

# pragma provides the compiler with special instructions for compiling the file in which it is displayed. The compiler should support the instructions. In other words, you can not use #pragma to create custom preprocessing instructions. The Microsoft C # compiler supports these two #pragma statements:

#pragma warning
#pragma checksum
    
06.06.2017 / 19:39