Essential C# Preprocessor directives  Suggest an edit

Disabling and Restoring Compiler Warnings

You can disable compiler warnings using #pragma warning disable and restore them using #pragma warning restore:

#pragma warning disable CS0168

// Will not generate the "unused variable" compiler warning since it was disabled
var x = 5;

#pragma warning restore CS0168

// Will generate a compiler warning since the warning was just restored
var y = 8;

Comma-separated warning numbers are allowed:

#pragma warning disable CS0168, CS0219

The CS prefix is optional, and can even be intermixed (though this is not a best practice):

#pragma warning disable 0168, 0219, CS0414

Table Of Contents
22 Enum
92 Preprocessor directives
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close