简体   繁体   English

该名称在当前上下文中不存在

[英]that name does not exist in current context

In case 3: I wrote mutteer(ba, bb, bc, bd, be); case 3:我写了mutteer(ba, bb, bc, bd, be); which seems to give the error ( The name ba does not exist in current context ). 这似乎给出了错误( 名称ba在当前上下文中不存在 )。 It gives the same error with bb bc bd and be . bb bc bdbe给出相同的错误。

What did I do wrong? 我做错了什么?

I removed most of the unnecessary code: 我删除了大多数不必要的代码:

static void menu()
    {
        int loop = 4;
        Console.WriteLine(" 3  Mutteer Voorraad");

        while (loop > 2)
            {
            var ans = Console.ReadLine();
            mp3();
            int choice = 0;
            if (int.TryParse(ans, out choice))
            {
                switch (choice)
                {
                    case 3:
                        Console.WriteLine("Mutteer Voorraad.");
                        mutteer(ba, bb,  bc, bd, be);
                        break;

                    default:
                        Console.WriteLine("Wrong selection!!!");
                        Thread.Sleep(1800);
                        Console.Clear();
                        goto top;
                }
            }
            else
            {
                Console.WriteLine("You must type numeric value only!!!");
                Thread.Sleep(1800);
                Console.Clear();
                goto top;
            }
        }
    }

static void mp3()
    {
        int ba = 500;
        int bb = 500;
        int bc = 500;
        int bd = 500;
        int be = 500;

        mp3players mp1 = new mp3players();
        mp1.id = 1;
        mp1.VR = ba;
     }

static void mutteer(int ba, int bb,  int bc, int bd, int be)
     {
        int i = 1;
        int a;

        startloop:
        while (i == 1)
            {
                Console.WriteLine("Wat is het Id van de mp3 speler?");
                try
                {
                    a = Convert.ToInt16(Console.ReadLine());
                }
                catch
                {
                    Console.WriteLine("Dat is geen nummer waarde!");
                    goto startloop;
                }

                if (a == 1)
                {
                    Console.WriteLine("Wat is het nieuwe voorraad");
                    try
                    {
                        i = 2;
                        ba = Convert.ToInt32(Console.ReadLine());
                    }
                    catch
                    {
                        Console.WriteLine("Dat is geen nummer waarde!");
                        goto startloop;
                    }
            }
        }

You need to move the declarations of ba and the other variables to the global scope. 您需要将ba的声明和其他变量移至全局范围。 As the code is currently written, they're accessible only in the scope of the mp3 method. 由于代码是当前编写的,因此只能在mp3方法的范围内访问它们。 You should have: 你应该有:

static int ba = 500;
static int bb = 500;
static int bc = 500;
static int bd = 500;
static int be = 500;

  static void mp3()
    {
    mp3players mp1 = new mp3players();
    mp1.id = 1;
    mp1.VR = ba;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM