0
for(int i = 1;i<=count;i++){
     1 string[] str = Console.ReadLine().Split(" ");
     2 int radius = Int32.Parse(str[0]);
     3 int horl = Int32.Parse(str[1]);
     4 int radius = Int32.Parse(Console.ReadLine());
     5 int horl = Int32.Parse(Console.ReadLine()); }

When I was trying to run the code for the line (1-3 it was running without any error but for the line (4-5) it is showing me formatexception input string was not in a correct format. input are like this: count value - 1 input value - 3 2 please tell why i am getting this error

Umang
  • 11
  • 3
  • 2
    Please provide the exact actual input, and specifically the values of `str[0]`, `str[1]`, and the result of each `Console.ReadLine();` – ProgrammingLlama Apr 24 '20 at 14:21
  • It's likely just a duplicate of [this](https://stackoverflow.com/questions/9372210/int-parse-input-string-was-not-in-a-correct-format) though. – ProgrammingLlama Apr 24 '20 at 14:22
  • OK, so the problems are with lines 4 and 5. Are you entering only numeric characters (from the set 0123456789) and the return/enter key into the Console? If you're entering a decimal point, it's not an integer. If you're entering a space before or after, it's not an integer. – ProgrammingLlama Apr 24 '20 at 14:24
  • It is probably a oversight. Did you type 3 2 and forget to call split on the failing line (4)? – Steve Apr 24 '20 at 14:24
  • Actually when I pass it as a array then it accepts the value whereas if I take value one by one it shows number format exception – Umang Apr 24 '20 at 14:27
  • Please include the exact console input values causing this problem. The error occurring is completely dependent upon the input being wrong. – ProgrammingLlama Apr 24 '20 at 14:39
  • A general hint: always use TryParse instead of Parse when you process user input as you usually don’t want to crash your application just because a user entered invalid data. – ckuri Apr 24 '20 at 19:40

0 Answers0