I started c# a month ago and suddenly got a thought that what happens if I don't enter anything for a int value. And I got a error! Would be great if you could help!
public static void NullChecker()
{
Console.Write("Age: ");
int age = Convert.ToInt16(Console.ReadLine());
if (age != null)
{
if (age >= 16)
{
Console.WriteLine("Welcome!");
}
else
{
Console.WriteLine("You are too young!");
Console.WriteLine("See you soon!");
}
}
else
{
Console.WriteLine("You cant leave it blank!");
}
}
I want to know that how do I know if he has entered nothing and redirect him back.Thank you!