I KEEP EXPERIENCING THE ERROR MESSAGE FOR THE CODE SHOWN BELOW. PLEASE ASSIST ME SUCH THAT I CAN HANDLE THE ERROR MESSAGE WHEN A | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I KEEP EXPERIENCING THE ERROR MESSAGE FOR THE CODE SHOWN BELOW. PLEASE ASSIST ME SUCH THAT I CAN HANDLE THE ERROR MESSAGE WHEN A

using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ //Dictionary<TKey, TValue> //Dictionary name_phone = new Dictionary(); int dictInput = Convert.ToInt32(Console.ReadLine()); Dictionary<string, int> name_phone = new Dictionary<string, int>(dictInput); //string[] phoneBook = new string[dictInput]; string name = ""; int phoneNumber = 0; for (int i=0;i< dictInput;i++){ name = Console.ReadLine().ToLower(); phoneNumber = Convert.ToInt32(Console.ReadLine()); name_phone[name] = phoneNumber; //Console.WriteLine(name_phone); } name = Console.ReadLine().ToLower(); if (name_phone.ContainsKey(name)==true) { Console.WriteLine("{0}={1}", name, phoneNumber); } else { Console.WriteLine("Not found"); } } } Unhandled Exception: System.FormatException: Input string was not in a correct format. at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x0001a] in <285579f54af44a2ca048dad6be20e190>:0 at System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00016] in <285579f54af44a2ca048dad6be20e190>:0 at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00017] in <285579f54af44a2ca048dad6be20e190>:0 at System.Convert.ToInt32 (System.String value) [0x0000b] in <285579f54af44a2ca048dad6be20e190>:0 at Solution.Main (System.String[] args) [0x00032] in <03bb6d4349d14d81a510961684ab1e47>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in a correct format.

12th Mar 2021, 3:05 PM
Adewale Isaac
Adewale Isaac - avatar
2 Answers
0
Kindly delete the duplicate question your posted. Thanks!
12th Mar 2021, 3:08 PM
Sharique Khan
Sharique Khan - avatar
0
Done. Please I need help with this error handling. Thanks
12th Mar 2021, 3:10 PM
Adewale Isaac
Adewale Isaac - avatar