Problem:
I would like to selectively disable C# warnings.
Solution:
The syntax to selectively disable warnings is:
#pragma warning disable <warning number or warning list>
<code block where warning is to be ignored>
#pragma warning restore <warning number or warning list>
Example:
#pragma warning disable 0618
MyNecessaryObsoleteFunctionCall();
#pragma warning restore 0618
BadObsoleteCallThatShouldProduceWarning();
Notes:
C# compiler warnings are generally there for good reason, so it's better practice to resolve them rather than hide them. However, in some situations willfully ignoring/acknowledging a warning might be necessary (e.g. if warnings block your team's build, but the code is temporarily required for some important reason).
No comments:
Post a Comment