Saturday 16 April 2016

Design a console application in which enter name of 10 students a Hash Table perform following operations:

Find out whether it contains student having name ‘X’ if it is not there then enter the name with key value 001.
Fetch all the keys of HashTable
Fetch all the value of HashTable
Remove any name of student from the HashTable
Empty HashTable

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable ht = new Hashtable();
            ht.Add("1", "PRATEEK");
            ht.Add("2", "Akshay");
            ht.Add("3", "Shubham");
            ht.Add("4", "Diksha");
            ht.Add("5", "Akshita");
            ht.Add("6", "Karan");
            ht.Add("7", "Rohit");
            ht.Add("8", "Zuber");
            ht.Add("9", "Vibhor");
            ht.Add("10", "Virat");
            ICollection key = ht.Keys;
            foreach (string k in key)
            {
                Console.WriteLine(k + ": " + ht[k]);
            }


            Console.WriteLine();
            if (ht.ContainsValue("Rohit"))
            {
                Console.WriteLine("It is There ");
            }
            else
            {
                ht.Add("7", "Rohit");
            }



            Console.WriteLine();
            Console.WriteLine("Table as per Values");
            ICollection value = ht.Values;
            foreach (string k in value)
            {
                Console.WriteLine(k  + ht[k]);
            }



            ht.Remove("8");
            Console.WriteLine();
            Console.WriteLine("Table After Removing An Element");
            foreach (string k in key)
            {
                Console.WriteLine(k + ": " + ht[k]);
            }

            Console.WriteLine();
            ht.Clear();
            Console.WriteLine("Empty Table");



         
 Console.ReadKey();
        }
    }
}

No comments:

Post a Comment