How do I prevent crashing from invalid user input?

后端 未结 3 996
北恋
北恋 2021-01-25 15:06

I have encountered a problem where my program crashes due to the input of the user not following the variable data type. What I am asking the user to do is register some data f

3条回答
  •  礼貌的吻别
    2021-01-25 15:23

    Use TryParse instead.

    Console.Write("Ange release: ");
    int release;
    while (!int.TryParse(Console.ReadLine(), out release))
    {
        Console.Write("Ange release: ");
    }
    

提交回复
热议问题