Reading an integer from user input

后端 未结 11 983
时光取名叫无心
时光取名叫无心 2020-11-22 09:44

What I am looking for is how to read an integer that was given by the user from the command line (console project). I primarily know C++ and have started down the C# path. I

11条回答
  •  鱼传尺愫
    2020-11-22 10:10

    int op = 0;
    string in = string.Empty;
    do
    {
        Console.WriteLine("enter choice");
        in = Console.ReadLine();
    } while (!int.TryParse(in, out op));
    

提交回复
热议问题