I would like to selectively disable C# warnings.
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>
#pragma warning disable 0618 MyNecessaryObsoleteFunctionCall(); #pragma warning restore 0618 BadObsoleteCallThatShouldProduceWarning();
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).