2017-04-30 1 views
1

나는이 코드를 사용자가 1 또는 2 등을 누를 수있게 해주는 몇 가지 switch-case 문과 함께 가지고있다. 그리고 다른 옵션들이 나타난다. 메서드 나 다른 것으로 cmd.exe의 이전 상태로 돌아갈 수 있는지 알고 싶습니까? 다시 말해, 버튼을 누르고 cmd.exe에서 새로운 팝업이 나오면 사용자가 3을 눌러서 cmd의 첫 번째 출력으로 돌아갈 수있는 switch case 문에 뭔가를 구현할 수 있습니까? 예를 들어 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-loop를 구현하면 언제든지 선택 사항을 반복해서 표시 할 수 있습니다. 먼저 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); 

.. Btw는

, 코드에 따라 , 반드시 goto 키워드가 필요하지 않습니다. 모든 코드가 실제로 전환되고 내부의 다른 스위치 인 경우 키워드 실행 전의 코드 실행이 루프의 끝까지 (do-while) 자동으로 실행됩니다.

관련 문제