Answer the question
In order to leave comments, you need to log in
Problem with random characters on input in C#?
Good day!
Such a problem:
When you run the code, when you need to input, the number 1 appears, which cannot be erased (Sometimes, the number that I entered can be duplicated)
When you input with a random character and another number, the output will be valid
But when you input only with a random character, this mistake:
unhandled exception. System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
Answer the question
In order to leave comments, you need to log in
DO NOT use Convert.ToInt32 or int.Parse unless you are sure you will have a 100% number as input. Use int.TryParse to avoid these errors. Vitaliy Kachan noticed correctly that your input is definitely not just a number.
So maybe there is another character besides a number? The error says that there is definitely not only a number, so it cannot parse. Maybe spaces, newline, tab, what else?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question