相关疑难解决方法(0)

变量在当前上下文中不存在?

我知道这很可能是一个愚蠢的问题,但我是一名大学生,他是C#和面向对象编程的新手.我试图在别处找到答案,但我找不到任何有用的东西.调试器一直告诉我变量'cust_num在当前上下文中不存在'.如果有人能告诉我我做错了什么并让我觉得自己像个白痴,我会非常感激.谢谢!

    string get_cust_num()
    {
        bool cust_num_valid = false;

        while (!cust_num_valid)
        {
            cust_num_valid = true;
            Console.Write("Please enter customer number: ");
            string cust_num = Console.ReadLine();

            if (cust_num == "000000" || !Regex.IsMatch(cust_num, @"^[0-9]+$") || cust_num.Length != 6)
            {
                cust_num_valid = false;
                Console.WriteLine("Invalid customer number detected. Customer numbers must be a 6 digit positive integer (zeros will not work)");
            }
        }

        return cust_num;
    }
Run Code Online (Sandbox Code Playgroud)

c# scope return

6
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×1

return ×1

scope ×1