How to disable Compiler warning messages using #pragma in C#

C# 4.0 allows you to explicitly suppress and restore compiler warnings using the #pragma warning

directive:

// Disable "The private field 'MyClass._age' is never used" warning

#pragma warning disable 169

public class MyClass

{

    int _age;

}

#pragma warning restore 169

Disabling warnings should be generally discouraged in production code. It is intended only for analysis when trying to isolate a problem, or when you lay out the code and would like to get the initial code structure in place without having to polish it up first. In all other cases, avoid suppressing compiler warnings.