Hi there,
you should save user's input as a string, then either try to parse it with
long.Parse(string) or first validate the string (with RegEx for example) and
then parse it if the string's valid input for a long value. If by any chance
the conversion doesn't work, you'll recive a FormatException, so it might be
a good idea to catch it. Something like the following:
long getInput()
{
while ( true )
{
string input = Console.ReadLine();
try
{
long value = long.Parse(input);
return value;
}
catch ( FormatException )
{
Console.WriteLine("Invalid input. Please enter a valid long value");
}
}
}
Cheers,
Branimir