1.i have to get input and store it to dictionary, and again get some input and check whether it is in dictionary or not.
2. I have tried this but giving the error (input string was not in correct format).
3. its not giving any error at compile time,but it is giving error at run time.whats the problem with this.
4. my inputs are: -
3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry
5. In place of Read(). I have also tried ReadLine(), but the problem is same.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main()
{
int n = Convert.ToInt32(Console.Read());
Dictionary<string, int> phbook = new Dictionary<string, int>();
for (int i = 0; i < n; i++)
{
string name = Console.Read().ToString();
int phonno = Convert.ToInt32(Console.ReadLine());
phbook.Add(name, phonno);
}
foreach (var keypairs in phbook)
{
string namet = Console.Read().ToString();
if (phbook.ContainsKey(namet))
{
Console.Write("{0}={1}", namet, phbook[namet]);
}
else
{
Console.Write("Not found");
}
}
}
}
The complete error is
Unhandled Exception:
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <a07d6bf484a54da2861691df910339b1>:0
at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00015] in <a07d6bf484a54da2861691df910339b1>:0
at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00008] in <a07d6bf484a54da2861691df910339b1>:0
at System.Convert.ToInt32 (System.String value) [0x0000b] in <a07d6bf484a54da2861691df910339b1>:0
at Solution.Main () [0x00034] in solution.cs:15
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <a07d6bf484a54da2861691df910339b1>:0
at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00015] in <a07d6bf484a54da2861691df910339b1>:0
at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00008] in <a07d6bf484a54da2861691df910339b1>:0
at System.Convert.ToInt32 (System.String value) [0x0000b] in <a07d6bf484a54da2861691df910339b1>:0
at Solution.Main () [0x00034] in solution.cs:15
Console.ReadLine()might not able to convert to int