Stupid Question 88: How do I ignore certain warnings in code when I’ve set treat all warnings as errors?
There might be times when you want to ignore warnings, sometimes all in a piece of code, sometimes just some certain warnings. There are a few ways to do that, for the whole project you can for example set that in the properties of the project. For just parts of the code you can use preprocessor directives (read more about them here: Stupid Question 52: What are preprocessor directives? (In c#)
Use :#pragma warning disable 414, 3021 (numbers are for specific warnings, if blank all warnings are disabled) and use #pragma warning restore 3021
to restore certain warnings, all or just certain warnings.
Here is an example (Warning level 4, treat all warnings as errors):
All warnings treated as errors
Ignoring warnings with preprocessor directives
Read more about the warning levels here:
Last modified on 2012-11-20