How to cancel action with key [closed]

-3

How to cancel an action, the code below is just an example :

    Console.WriteLine("Digite algo");
        string text = Console.ReadLine();
                            switch (){
    case "comando": //

> Aqui seria para cancelar com a tecla ESC, e voltar para a primeira
> linha do código
    Console.WriteLine("Digite algo");
    Console.ReadLine();
    Console.WriteLine("Digite outra coisa");
    Console.ReadLine();
}
    
asked by anonymous 30.08.2017 / 14:57

1 answer

0

I found your question very confusing, but from the comment you made, I think you want something like the code below:

string text = string.Empty;

do{
    Console.WriteLine("Digite algo");
    text = Console.ReadLine();
} while (text != "alguma_coisa_invalida");

switch (text){
    case "alguma_coisa_valida":
        //todo
        break;
    case "outra_coisa_valida":
        //todo
        break;
    case "mais_uma_coisa_valida":
        //todo
        break;
    default:
        //todo
        break;
}

explaining: the code reads the user input and validates if it is something accepted. If so, enter the case, otherwise, continue to wait for an ok entry.

    
30.08.2017 / 15:15