Visual Studio says variable “does not exist in current context” despite declaration being on the line before it (C#)

0
39

Visual Studio Gives the “Variable Does Not Exist in Current Context” even though the variable is defined in the line above where i’m trying to access it.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    string a = "";

    a = "";
//    ^ where the error occurs    
}

The Error:

IDE1007  The Name 'a' does not exist in current context.

In all the time I have used Visual Studio, I have never encountered this bug.

It is also useful to note that I have tried changing the build to debug and rebuilding, but to no avail.

LEAVE A REPLY

Please enter your comment!
Please enter your name here