Iris Classon
Iris Classon - In Love with Code

Stupid Question 88: How do I ignore certain warnings in code when I’ve set treat all warnings as errors?

[To celebrate my first year of programming I will ask a ‘stupid’ questions daily on my blog for a year, to make sure I learn at least 365 new things during my second year as a developer]

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:

Stupid Question 87: Warning levels, what are they, which level to use, and should they be treated as errors?

Comments

Leave a comment below, or by email.

Last modified on 2012-11-20

comments powered by Disqus