#118 – Disabling Specific Compiler Warnings

There are times when you knowingly want to include C# code in your program that generates a warning.

For example, the following code will generate a warning at compile time:

 static void Main(string[] args)
 {
     uint x = 0x1234;
 }

The warning appears in the Output window – CS0219: The variable ‘x’ is assigned but its value is never used.

If you’re aware of what this warning means, you don’t intend to change the source code to resolve it, and you want to no longer see the warning for this particular line, you can use the #pragma warning directive.  Place the directive immediately above the offending line and reference warning #219.

 static void Main(string[] args)
 {
#pragma warning disable 219
     uint x = 0x1234;
 }

You’ll no longer get warning #219 for this line when you compile.

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers