#pragma warning (C# Reference)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

#pragma warning can enable or disable certain warnings.

#pragma warning disable warning-list  
#pragma warning restore warning-list  


A comma-separated list of warning numbers. The "CS" prefix is optional.

When no warning numbers are specified, disable disables all warnings and restore enables all warnings.

System_CAPS_ICON_note.jpg Note

To find warning numbers in Visual Studio, build your project and then look for the warning numbers in the Output window.

// pragma_warning.cs  
using System;  
#pragma warning disable 414, CS3021  
public class C  
    int i = 1;  
    static void Main()  
#pragma warning restore CS3021  
[CLSCompliant(false)]  // CS3021  
public class D  
    int i = 1;  
    public static void F()  

C# Reference
C# Programming Guide
C# Preprocessor Directives
C# Compiler Errors