format exceptions was unhandled in int.parse
-
30-06-2021 - |
Domanda
I'm getting this exception
FormatException was unhandled, input string was not in a correct format.
at the following statement
int amnt = int.Parse(Console.ReadLine());
what should I do to solve it?
Soluzione
I would suggest the following:
int parsedInt = 0;
if (int.TryParse(Console.ReadLine(), out parsedInt))
{
//do success work
}
else
{
//do failed work
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow