Is there a way to convert a string to an integer?

Hi, I’m really new to C# and I’m trying to figure out how to convert a string to an integer. I’m trying to make a number guesser where you guess a number 1-10 and it tells you if you guessed too low or high or whatever. I don’t know how to show the code so I’m just gonna copy and paste it. Don’t mind the Convert.ToInt I was just desperate and trying to figure it out. If anything else is wrong I would appreciate help with that too.
Console.WriteLine(“Hey! Pick a number 1-10!”);
string guess = Console.ReadLine();
int answer = 5;
int number = Convert.ToInt(guess);
bool tooLow = guess < answer;
if (tooLow == true)
Console.WriteLine(“Too Low!”);

Hello, @firetire1, and welcome to the forums.

Research/Google int.Parse() and int.TryParse().
Microsoft Docs

1 Like