How do I prevent crashing from invalid user input?

后端 未结 3 1110
北恋
北恋 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:32

    Use Int32.TryParse() and handle the case when it's not an integer. The return value indicates whether the operation succeeded.
    For more information see http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx

提交回复
热议问题