#pragma warning (C# 參考)#pragma warning (C# Reference)

#pragma warning 可以啟用或停用特定警告。#pragma warning can enable or disable certain warnings.

語法Syntax

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

參數Parameters

warning-list
警告編號的逗點分隔清單。A comma-separated list of warning numbers. "CS" 前置詞是選擇性的。The "CS" prefix is optional.

未指定警告編號時,disable 會停用所有警告,而 restore 會啟用所有警告。When no warning numbers are specified, disable disables all warnings and restore enables all warnings.

注意

若要尋找 Visual Studio 中的警告編號,請建立專案,然後在 [輸出] 視窗中尋找警告編號。To find warning numbers in Visual Studio, build your project and then look for the warning numbers in the Output window.

範例Example

// pragma_warning.cs  
using System;  
  
#pragma warning disable 414, CS3021  
[CLSCompliant(false)]  
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()  
    {  
    }  
}  

另請參閱See also