#pragma warning disable & restore

At the very least you should be specific about which warnings you’ve deliberately chosen to ignore. That way, if later maintenance introduces a ‘new’ warning/issue that you should be made aware of, the warning about the newly-introduced error won’t be suppressed by your blanket pragma warning disable directive.

You can get the warning numbers pertaining to the build issues you’ve decided to ignore from the build Output window in Visual Studio. They’re usually labelled “Warning CS0168….” or similar. In which case you can specifically target just the those error(s) you’ve decided to ignore like so:

#pragma warning disable 168, 3021

    //Your code that generates warnings CS0168 and CS3021 here

#pragma warning restore 168, 3021

Leave a Comment