Logynymo Logynymo - 10 days ago 5
C# Question

"Implicitly-typed variables must be initialized"

enter image description here

I have just started my learning experience with c# and this problem has been teasing me. Please help :)

Answer

You need to use int.TryParse to be safe, otherwise a wrong input would throw an error.

string userAgeInput = Console.Readline();
int userAge = 0;

if (!int.TryParse(userAgeInput, out userAge))
    Console.WriteLine("Please input a valid age!");

Now you can compare userAge.

if (userAge >= 18)
Comments