James Ray Anderson

James Ray Anderson
James Ray Anderson
0 comments

Disable or Restore Compiler Warnings in Visual Studio 2008

11:10 AM
You can Disable and Restore compiler warnings in your code using the #pragma directive. The #pragma directive gives the compiler special instructions for the file that is being compiled. The format for disabling and restoring compiler warnings is:

#pragma warning [disable/restore]

The is a comma separated list of warning numbers without the "CS" prefix. In your compiler output you may get a warning, such as:

...warning CS0168: The variable 'ex' is declared but never used
You can use the #pragma directive to specifically ignore one or more warnings. For Example:

#pragma warning disable 0168
You can add multiple entries by separating them with a comma. It is also a good idea to comment the directive so that others can understand what is being suppressed.

//Disabling: warning CS1591: Missing XML comment for publicly visible type or member 'val' for this class
//Disabling: warning CS1717: Assignment made to same variable; did you mean to assign something else? [then your reason]
#pragma warning disable 1591, 1717
You can restore the warnings by replacing disable with restore. For more information you can visit http://msdn.microsoft.com/en-us/library/441722ys.aspx

0 comments:

 
Toggle Footer
Top