Convert String to int in C#

前端 未结 5 1880
星月不相逢
星月不相逢 2020-12-11 08:10

I am trying to write a simple program that asks the user to enter a number and then I will use that number to decide what the cost of the ticket will be for their given age.

5条回答
  •  既然无缘
    2020-12-11 08:22

    Try the int.TryParse(...) method. It doesn't throw an exception.

    http://msdn.microsoft.com/en-us/library/f02979c7.aspx

    Also, you should use && not & in your conditions. && is logical AND and & is bitwise AND.

提交回复
热议问题