Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

#pragma warning (C# Reference)

#pragma warning can enable or disable certain warnings.

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

A comma-separated list of warning numbers. Enter the numbers alone, without the "CS" prefix.

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

NoteNote

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, 3021
[CLSCompliant(false)]
public class C
{
    int i = 1;
    static void Main()
    {
    }
}
#pragma warning restore 3021
[CLSCompliant(false)]  // CS3021
public class D
{
    int i = 1;
    public static void F()
    {
    }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.