开发者

C# Error 1 A local variable named 'userin' is already defined in this scope

开发者 https://www.devze.com 2023-01-16 08:52 出处:网络
Error1A local variable named \'userin\' is already defined in this scope myclass.fillAccounts(); //int i = 0;

Error 1 A local variable named 'userin' is already defined in this scope

    myclass.fillAccounts();

        //int i = 0;
        //while (i != 1)

        string userin = null;

        while (userin !="x") 
        {
            //use the following me开发者_如何转开发nu:            
            Console.WriteLine("*****************************************");
            Console.WriteLine("enter an a or A to search account numbers");
            Console.WriteLine("enter a b or B to average the accounts");
            Console.WriteLine("enter an x or X to exit program");
            Console.WriteLine("*****************************************");
            Console.Write("Enter option-->");
            userin = Console.ReadLine();
            if (userin == "a" || userin == "A")
            {
                myclass.searchAccounts();
            }
            else if (userin == "b" || userin == "B")
            {
                myclass.averageAccounts();
            }
            else if (userin == "x" || userin == "X")
            {
              break;
            }

            else
            {
                Console.WriteLine("You entered an invalid option");
            }
        }
    }
}

}


Somewhere else in that method in the code you did not provide, you already have a line of code that says something like this:

string userin;

You have later said:

string userin = null;

Which is attempting to redefine a local variable. Get rid of the first variable declaration and you should be good to go for this issue. (You want to keep the declaration with the initial value, because you need that variable initialized by the time the while condition is evaluated.)


If this is all the code from the method then likely you have a field on the class named userin. Is this a partial class? Is it a WPF/Winforms/Webforms class? Perhaps you have a control named userin?

0

精彩评论

暂无评论...
验证码 换一张
取 消