我试图在一个非常简单的C#文件中禁止显示警告,但是它不起作用,在这里我找不到做错的事情。为什么Visual Studio在这一小段代码中仍显示“检测到无法访问的代码”。
#pragma warning disable 429
// I've got the number from:
// http://msdn.microsoft.com/en-us/library/2ch1a3w5.aspx
// This below does work, so I might have the wrong number for the warning?
// #pragma warning disable
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("test");
if (false)
return;
return;
MessageBox.Show("test");
}
}
}
最佳答案
我不确定为什么要禁用429,但是要禁用0162-这是您得到的警告编号:
#pragma warning disable 0162
始终在构建输出中查找特定的警告编号。
(当然,无论如何,禁用警告通常不是一个好主意……尝试修复代码而不是禁用警告。)
关于c# - 为什么警告禁用429无法抑制无法访问的代码?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23387360/