CSharp - Preprocessor Directives Pragma Warning


The compiler allows you to suppress warnings with the #pragma warning directive.

In this example, we instruct the compiler not to warn us about the field Message not being used:

public class Test
       static void Main() { }
       #pragma warning disable 414
       static string Message = "Hello";
       #pragma warning restore 414

Omitting the number in the #pragma warning directive disables or restores all warning codes.

If you are thorough in applying this directive, you can compile with the /warnaserror switch-this tells the compiler to treat any residual warnings as errors.