为什么警告禁用429无法对无法访问的代码进行操作
本文关键字:代码 操作 访问 警告 为什么 | 更新日期: 2023-09-27 18:01:00
我试图在一个非常简单的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
始终在生成输出中查找特定的警告编号。
(当然,禁用警告通常不是一个好主意……试着修复代码,而不是禁用警告。(