C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: By wrapping the #pragma warning disable directive and #pragma warning restore directive around the statement, we can hide the warning.
So: When you compile this program, no warnings are reported by the C# compiler.
C# program that uses pragma directive
using System;
class Program
{
static void Main()
{
// This example has unreachable code!
// ... The pragma directives hide the warning.
#pragma warning disable
if (false)
{
Console.WriteLine("Perls");
}
#pragma warning restore
}
}
However: This is probably more trouble than it is worth. It might be better to just disable all warnings in small blocks of code.
And: This ensures that the code will not stop compiling and refactoring will update it.
Review: I can use the #pragma directives to indicate that I know the code is unreachable already and don't want to fix it.