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");
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.