What is #pragma c#

Asked

Viewed 755 times

5

By maintaining a code of a web service I came across the following code snippet:

#pragma warning disable 1591

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

Question

What is #pragma ? And when to be used ?

  • Related: https://answall.com/questions/155564/utilidade-do-pragma/155570?s=1|2.5521#155570

2 answers

3

The #pragma provides the compiler with special instructions for compiling the file in which it is displayed. The compiler must support the instructions. In other words, it is not possible to use #pragma to create custom pre-processing instructions. The Microsoft C# compiler supports these two #pragma instructions:

#pragma warning
#pragma checksum

3


The #pragma serves to pass specific instructions to the compiler

To use must inform as follows #pragma nome-configuracao argumentos

In the following example it is disabled the warnings for the test code snippet, you can notice that there is a variable that is declared and is not used, this naturally would display a Warning in the build, but as we disable it will not be displayed

#pragma warning disable warning-list  
public void teste(){
    string naoUtiliza = "Teste";
    return "Teste";
}
#pragma warning restore warning-list  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.