2017-04-30 7 views
1

私はこのコードを、ユーザーが1または2などを押すことを可能にするいくつかのswitch-caseステートメントとともに持っており、いくつかの他のオプションがポップアップします。私は方法または何か他のcmd.exeで前の状態に戻ることが可能かどうかを知りたがっていましたか?つまり、ボタンが押されて何か新しいcmd.exeがポップアップすると、ユーザーが例えば3を押してcmdの最初の出力に戻ることができるswitch caseステートメントに何かを実装することが可能になります。 exeと1のプッシュ後に出てきた出力を消去する?cmd.exeのポイントから前のポイントに戻る可能性はありますか?

switch (userValue) 
    { 
     case '1': 
      Console.WriteLine("\n" + "You have entered a default 
tournament:" + "\n"); 
      Console.Write("Press 1 to start the first tournament" + "\n" + "Press 2 to start the second tournament + "\n" + "Press 3 to return"; 
          + "\n" + "Insert your choice...: "); 
      var userType = Console.ReadKey().KeyChar; 
      Console.WriteLine(); 
      { 
       switch (userType) 
       { 
        case '1': 
         Console.WriteLine("something"); 
         break; 
        case '2': 
         Console.WriteLine("something"); 
         break; 
        case '3': 
         //WHAT TO DO HERE??? 
       } 
       break; 
      } 
     case '2': 
      Console.WriteLine("\n" + "You have entered women's single"); 
      Console.Write("Press 1 to start the tournament:" + "\n" + "Press 2 to list the players by first name:" + "\n" + 
       "Press 3 to list the players by last name:" + "\n" + "Insert your choice...: "); 
      var userChoice = Console.ReadKey().KeyChar; 
      Console.WriteLine(); 
      { 
       switch (userChoice) 
       { 
        case '1': 
         SelectTournamentMenu(); 
         break; 
        case '2': 

         break; 
        case '3': 

         break; 
       } 

答えて

0

あなたはこれらの選択が含まれていたdo-whileループを実装する場合は、あなたはいつも何度も何度も選択を表示することができます。最初にConsole.Clear()を押して、画面を空にすることができます。ユーザーのためのあなたの選択が他のものを実行した後に繰り返されていることをしたい場合は、あなたが今、出口ブール値を使用することができます例えば

bool exit = true; 
do 
{ 
    exit = true; 
    Console.WriteLine("Your options are.."); //print options for user here! 

    switch..... // put your multiple switch statements here! 
    (etc) 
    case 3: 
    exit = false; // this is how you start it all over again! 
    goto end; 
    break; 

:end // please notice that goto can only jump forward 
} 
while(!exit); 

...ところで

、あなたのコードに応じて、必ずしもgotoキーワードは必要ありません。すべてのコードが本当にスイッチであり、その内部の別のスイッチである場合、コードの実行はwhileキーワードの前にループの最後まで(do-whileで)自動的に実行されます。

関連する問題