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?
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.
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.
If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option. Inhibit all warning messages. Make all warnings into errors.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With