Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 887
Nosrama Avatar asked Sep 04 '09 11:09

Nosrama


People also ask

Can I ignore warning messages from my compiler?

Unlike compilation errors, warnings don't interrupt the compilation process. They are not errors from the viewpoint of a programming language, but they may be software bugs. However, many compilers can be customized so that their warnings don't stop the compilation process. Warnings must not be ignored.

How do you supress a warning in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

Which option of GCC inhibit all warning messages?

If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option. Inhibit all warning messages. Make all warnings into errors.


1 Answers

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).

like image 79
Tamás Szelei Avatar answered Sep 18 '22 19:09

Tamás Szelei