-3

あるスイッチ ケースから別のスイッチ ケースに移動したい:

Switch()
{ 

}
c=console.readline();
switch(yup)
{
   case y:
   "I WANT TO CALL SWITCH 1;"
   case n:
   EXIT;
}
4

4 に答える 4

1

If you want to "call another switch" you have to extract it into a seperate method, and invoke that instead.

public static void Main()
{
    MethodWithFirstSwitch();        

    c=console.readline();

    switch(yup)
    {
        case y:
        MethodWithFirstSwitch();
        case n:
        EXIT;
    }
}

private static void MethodWithFirstSwitch()
{
     switch(something)
     {
          case "something":
          break;
          default:
          break;
     }
}

I'm not sure if this is an accurate aproximation of your problem. That you have a switch, then always want to run some code, followed by a new switch, with one of the cases running the same switch as previously.

This will not run as is of course, due to the non existing variables and EXIT; call but serves as an example.

If this doesn't answer your question then please update original post with more detail of what you are trying to achieve.

于 2012-09-01T06:50:23.260 に答える
0

私はこれがあなたが望むものだと思います:-

switch(yup)
{
   case y:
   {
       //call your switch inside case y
       switch()
       {
         ----
         ----
       }
   }

   case n:
   EXIT;
}
于 2012-09-01T06:47:56.687 に答える
0

あなたが求めていることを文字通り行うには、goto. ただし、ほとんどの人は、gotoコードの理解、デバッグ、保守が非常に難しくなるため、非常に嫌いです。

通常、do/whileループを使用して、終了する準備ができたときに設定した変数をチェックします。このようなもの:

bool done = false;

do
{
    switch(/* ... */)
    {
        // ...
    }

    c = Console.ReadLine();

    switch(yup)
    {
        case y:
            break;
        case n:
            done = true;
            break;
    }
}
while(!done);
于 2012-09-01T06:49:32.730 に答える
0
 private void Form1_Load(object sender, EventArgs e)
    {
        MyFirstSwitch(true);
        //c=console.readline();
        string yup;
        switch (yup)
        {
            case "y":
                MyFirstSwitch(false);
                break;
            case "n":
                //Exit
                break;
        }
    }

    private void MyFirstSwitch(bool check)
    {
        switch (check)
        {
            case true:
                //Do some thing hereZ
                break;

            case false:
                //Do some thing hereZ
                break;
        }
    }
于 2012-09-01T06:55:33.670 に答える