为什么警告禁用429无法抑制无法访问的代码?

时间:2014-04-30 11:51:53

标签: c# compiler-warnings pragma

我试图在一个非常简单的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");
        }
    }
}

1 个答案:

答案 0 :(得分:6)

我不确定你为什么禁用429,但你想禁用0162 - 这是你得到的警告号码:

#pragma warning disable 0162

始终在构建输出中查找特定的警告编号。

(当然,无论如何禁用警告通常都不是一个好主意......尝试修复代码而不是禁用警告。)