This works perfectly, except that when the user enters an number with a decimal (e.g. 2.3), it returns the same statement (“Number must be an integer”).
I am trying to say if it is not an int OR a double.
Code:
while (true)
{
Console.Write("Enter First Integer:");
string line = Console.ReadLine();
if (!int.TryParse(line, out firstNo)) //INT OR A DOUBLE
Console.WriteLine("Number must be an integer. {0} is not an integer.", line);
break;
}
Parse it as
double, it would work both with integers and decimals:Remember that
.or,separator may differ depending on your current culture.So, if you need to separate int ans doubles, do smth like this: