using System;
using System.Collections;
using System.IO;
class MobileBook
{
static void Main(string[] arg)
{
Hashtable tab = new Hashtable();
string fileName;
if
{
(arg.Length > 0) fileName = arg[0];
}
else
{
fileName = "MobileBook.txt";
}
StreamReader r = File.OpenText(fileName);
string line = r.ReadLine();
while (line != null)
{
int pos = line.IndexOf('=');
string name = line.Substring(0, pos).Trim();
long Mobile= Convert.ToInt64(line.Substring(pos + 1));
tab[name] = Mobile;
line = r.ReadLine();
}
r.Close();
for (; ; )
{
Console.Write("Name : ");
string name = Console.ReadLine().Trim();
if (name == "")
break;
object Mobile= tab[name];
if (Mobile== null)
Console.WriteLine("-- Not Found in Mobile Book");
else
Console.WriteLine(Mobile);
}
}
}
-------------
OUTPUT:-
Name : Kamal
8899945777
Name : Suresh
-- Not Found in Phone Book
---------------------------------
No comments:
Post a Comment