Question

I am trying to suppress a warning in a very simple C# file, but it is not working and I cannot find what I am doing wrong here. Why is Visual Studio still showing "Unreachable code detected" in this small piece of code.

#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");
        }
    }
}
Was it helpful?

Solution

I'm not sure why you're disabling 429, but you want to disable 0162 - that's the warning number you're getting:

#pragma warning disable 0162

Always look for the specific warning number in the build output.

(And of course, it's generally not a good idea to disable warnings anyway... try to fix the code rather than disabling the warning.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top