Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

后端 未结 8 1037
北恋
北恋 2020-12-03 16:59

Is there a way to suppress warnings in C# similar to Java\'s @SuppressWarnings annotation?

Failing that, is there another way to suppress warnings in Visual Studio?<

8条回答
  •  长情又很酷
    2020-12-03 17:11

    There is. See the MSDN page on how to suppress compiler warnings.

    From Visual Studio, go to your project properties, select the build tab, and enter the warning number in the Suppress Warnings field.

    From code, to disable specific warnings, you can use the #pragma directive:

    public class MyClass
    {
      #pragma warning disable 0168
      // code
    
      // optionally, restore warnings again
      #pragma warning restore 0168
      // more code
    }
    

提交回复
热议问题