Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

Nosrama picture Nosrama · Sep 4, 2009 · Viewed 19.4k times · Source

Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

Failing that, is there another way to suppress warnings in Visual Studio?

Answer

Tamás Szelei picture Tamás Szelei · Sep 4, 2009

Yes.

For disabling, use:

#pragma warning disable 0169, 0414, anyothernumber

Where the numbers are the identifiers of the warnings that you can read from compiler output.

To reenable the warnings after a particular part of code (which is a good idea) use:

#pragma warning restore 0169, anythingelse

This way you can make the compiler output clean, and keep yourself safe because the warnings will only be suppressed for that particular part of code (where you made sure you don't need to see them).