58. HashTable In C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace HashTable
{
class Program
{
static void Main(string[] args)
{
Hashtable h1 = new Hashtable();
h1.Add("s1", "Milan");
h1.Add("s2", "Bakotra");
h1.Add("s3", "Divi");
h1.Add("s4", "Divu");
h1.Add("s5", "Vidhi");
foreach (DictionaryEntry sname in h1)
{
Console.WriteLine("Key : " + sname.Key + " And Value : " + sname.Value);
}
Console.WriteLine("ContainsKey() : " + h1.ContainsKey("s3"));
Console.WriteLine("Contains() : " + h1.Contains("s6"));
Console.WriteLine("ContainsValue() : " + h1.ContainsValue("Vidhi"));
Console.WriteLine("===== Display All Key =====");
foreach (String keys in h1.Keys)
{
Console.WriteLine(keys);
}
Console.WriteLine("===== Display All Values =====");
foreach (String values in h1.Values)
{
Console.WriteLine(values);
}
Console.WriteLine("===== After Remove =====");
h1.Remove("s3");
foreach (String keys in h1.Keys)
{
Console.WriteLine(keys);
}
Console.WriteLine("===== Display All Values =====");
foreach (String values in h1.Values)
{
Console.WriteLine(values);
}
Console.WriteLine("Total Element : " + h1.Count);
Console.Read();
}
}
}
Comments
Post a Comment