-1

Is there a general rule about disabling warnings in your code?

In my particular case, an unreachable code warning was issued because of an if statement testing a constant value, where it could be replaced with a compilation directive.

I believe that code where you have 100% of control over should never require #pragma warning disable XXXX.

Doc Brown
  • 218,378
Roberto
  • 193
  • 7

1 Answers1

4

Use #pragma warning disable XXXX when:

  1. You have a legitimate reason for the warning appearing, and
  2. You don't want to see the warning, and
  3. You document your legitimate reason.

An illustrative example might be a try statement with an empty catch block, where the catch block is there to intentionally swallow an exception that is thrown by some library you can't control, and swallowing the exception is the only reasonable course of action.

Robert Harvey
  • 200,592