あるスイッチ ケースから別のスイッチ ケースに移動したい:
Switch()
{
}
c=console.readline();
switch(yup)
{
case y:
"I WANT TO CALL SWITCH 1;"
case n:
EXIT;
}
あるスイッチ ケースから別のスイッチ ケースに移動したい:
Switch()
{
}
c=console.readline();
switch(yup)
{
case y:
"I WANT TO CALL SWITCH 1;"
case n:
EXIT;
}
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.
私はこれがあなたが望むものだと思います:-
switch(yup)
{
case y:
{
//call your switch inside case y
switch()
{
----
----
}
}
case n:
EXIT;
}
あなたが求めていることを文字通り行うには、goto
. ただし、ほとんどの人は、goto
コードの理解、デバッグ、保守が非常に難しくなるため、非常に嫌いです。
通常、do
/while
ループを使用して、終了する準備ができたときに設定した変数をチェックします。このようなもの:
bool done = false;
do
{
switch(/* ... */)
{
// ...
}
c = Console.ReadLine();
switch(yup)
{
case y:
break;
case n:
done = true;
break;
}
}
while(!done);
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;
}
}