Convert String to int in C#

前端 未结 5 1877
星月不相逢
星月不相逢 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:36

    The first thing you need to do is change your input variable to a string:

    string input = Console.ReadLine();
    

    Once you have that, there are several ways to convert it to an integer. See this answer for more info:
    Better way to cast object to int

提交回复
热议问题