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

JaJ*_*aJa 1 c# pragma compiler-warnings

我试图在一个非常简单的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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 6

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

#pragma warning disable 0162
Run Code Online (Sandbox Code Playgroud)

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

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