Tuesday, 27 November 2012

Dictionary in console Application

using System;
using System.Collections;
using System.Text;

namespace dictionary
{
class Program
{
static void Main(string[] args)
{
SortedList s = new SortedList();
string name, word;
int ch=0,n;
while (ch < 4)
{
Console.WriteLine("MENU");
Console.WriteLine("1.ADD");
Console.WriteLine("2.SEARCH");
Console.WriteLine("3.DELETE");
Console.WriteLine("4.EXIT");
Console.WriteLine("Enter your Choice");
ch = int.Parse(Console.ReadLine());

switch (ch)
{
case 1:
{
Console.WriteLine("Enter no of words");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the words & meaning one by one");
for (int i = 0; i <= n; i++)
{
word = Console.ReadLine();
name = Console.ReadLine();
s.Add(word, name);
}
Console.WriteLine("words to be added");
foreach (DictionaryEntry elt in s)
{
Console.WriteLine(elt.Key + ":" + elt.Value);
}
break;
}
case 2:
{
Console.WriteLine("Enter the word to be search");
word = Console.ReadLine();
if (s.ContainsKey(word))
Console.WriteLine(word + ":" + s[word]);
else
Console.WriteLine("word not found");
break;
}
case 3:
{
Console.WriteLine("Enter the word to be delete");
word = Console.ReadLine();
if (s.ContainsKey(word))
{
s.Remove(word);
foreach (DictionaryEntry elt in s)
{
Console.WriteLine(elt.Key + ":" + elt.Value);
}
}
else

Console.WriteLine("word not found");
break;

}
}
}


}
}
}

No comments:

Post a Comment