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

后端 未结 8 1041
北恋
北恋 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条回答
  •  猫巷女王i
    2020-12-03 17:20

    Yes.

    For disabling, use:

    #pragma warning disable 0169, 0414, anyothernumber
    

    Where the numbers are the identifiers of the warnings that you can read from compiler output.

    To reenable the warnings after a particular part of code (which is a good idea) use:

    #pragma warning restore 0169, anythingelse
    

    This way you can make the compiler output clean, and keep yourself safe because the warnings will only be suppressed for that particular part of code (where you made sure you don't need to see them).

提交回复
热议问题