Nov 202012
 
 November 20, 2012  Posted by at 11:42 pm C# & F#, Dev Environment, Not So Stupid Questions  Add comments

[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

All warnings treated as errors

Ignoring warnings with preprocessor directives

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?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 6 + 10 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)