#1,128 – Disable a Compile-Time Warning for Entire Project

You can use #pragma warning to selectively disable certain warnings that occur when compiling your code.  When #pragma warning disable is encountered, the specified warning will be disabled for the current file, from the point where the pragma appears until the end of the file, or until a #pragma warning restore is encountered for the same warning.

If you want to disable a particular warning for all files compiled in a project, rather than just within a single file, you can add the warning number to the Suppress warnings field on the Build tab in the project properties window.  This will suppress the specified warning for the entire project.

1128-001

1128-002

Advertisement

#1,127 – Where to Find Compiler Warning Numbers

You can use #pragma warning to selectively disable certain warnings that occur when compiling your code.

The #pragma warning line requires knowing the specific warning number, which is not displayed in the list of warnings on the Error List tab.

1127-001

To find the warning number, you need to switch to the Output tab and look at the full text of the warning.  In the example below, we see that the warning about an event that is never used is warning #67.

1127-002

Once you know the warning number, you can use it with a #pragma warning.

#pragma warning disable 67
        public event EventHandler CanBarkChanged;
#pragma warning restore 67