Logynymo Logynymo - 1 year ago 147
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 Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download