उदाहरण 1: Hashtable में कुंजी जांचना
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add("One", "Katie");
hash.Add("Two", "John");
hash.Add("Three", "Barry");
hash.Add("Four", "");
hash.Add("Five", "Harry");
hash.Add("Six", "F");
hash.Add("Seven", "Tom");
hash.Add("Eight", "Andy");
hash.Add("Nine", "I");
hash.Add("Ten", "Tim");
Console.WriteLine("Hashtable कुंजी और मान जोड़े...");
foreach(DictionaryEntry entry in hash) {
Console.WriteLine("{0} और {1} ", entry.Key, entry.Value);
}
Console.WriteLine("क्या Hashtable का आकार निश्चित है? = " + hash.IsFixedSize);
Console.WriteLine("क्या Hashtable केवल पढ़ने योग्य है? = " + hash.IsReadOnly);
Hashtable hash2 = Hashtable.Synchronized(hash);
Console.WriteLine("क्या Hash सिंक्रनाइज़्ड है? = " + hash2.IsSynchronized);
Console.WriteLine("क्या Hashtable में कुंजी Ten है? = " + hash.Contains("Ten"));
}
}
आउटपुट
Hashtable कुंजी और मान जोड़े...
One और Katie
Ten और Tim
Five और Harry
Three और Barry
Seven और Tom
Two और John
Four और
Eight और Andy
Nine और I
Six और F
क्या Hashtable का आकार निश्चित है? = False
क्या Hashtable केवल पढ़ने योग्य है? = False
क्या Hash सिंक्रनाइज़्ड है? = True
क्या Hashtable में कुंजी Ten है? = True
उदाहरण 2: मौजूद न होने वाली कुंजी जांचना
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add("1", "AB");
hash.Add("2", "BC");
hash.Add("3", "DE");
hash.Add("4", "EF");
hash.Add("5", "GH");
hash.Add("6", "IJ");
hash.Add("7", "KL");
hash.Add("8", "MN");
hash.Add("9", "OP");
hash.Add("10", "QR");
Console.WriteLine("कुंजी 3 पर मान = " + hash["3"]);
Console.WriteLine("क्या Hashtable में कुंजी 12 है? = " + hash.Contains("12"));
}
}
आउटपुट
कुंजी 3 पर मान = DE
क्या Hashtable में कुंजी 12 है? = False