有没有办法抑制C#警告类似于Java的@SuppressWarnings注释? [英] Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

查看:262
本文介绍了有没有办法抑制C#警告类似于Java的@SuppressWarnings注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法抑制C#警告类似于Java的@SuppressWarnings注释?

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

如果做不到这一点,是有另一种方式来抑制在Visual Studio中的警告?

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

推荐答案

禁用,则使用

#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).

这篇关于有没有办法抑制C#警告类似于Java的@SuppressWarnings注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆