Hashtable Dictionary से धीमा है। दृढ़ता से टाइप किए गए संग्रह के लिए, Dictionary संग्रह तेज़ है।
Hashtable
Hashtable क्लास कुंजी-और-मान जोड़े के संग्रह को दर्शाता है जो कुंजी के हैश कोड के आधार पर व्यवस्थित होते हैं। यह संग्रह में तत्वों तक पहुंचने के लिए कुंजी का उपयोग करता है।
आइए एक उदाहरण देखें:
उदाहरण
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
Hashtable ht = new Hashtable();
ht.Add("E001", "Tom");
ht.Add("E098", "Amit");
ht.Add("E110", "Jack");
ICollection key = ht.Keys;
foreach (string k in key) {
Console.WriteLine(k + ": " + ht[k]);
}
Console.ReadKey();
}
}
}
आउटपुट
E001: Tom E098: Amit E110: Jack
Dictionary
Dictionary C# में कुंजियों और मानों का संग्रह है। Dictionary<TKey, TValue> System.Collection.Generics नेमस्पेस में शामिल है।
उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
IDictionary<int, int> dict = new Dictionary<int, int>();
dict.Add(1, 234);
dict.Add(2, 489);
dict.Add(3, 599);
dict.Add(4, 798);
dict.Add(5, 810);
dict.Add(6, 897);
dict.Add(7, 909);
Console.WriteLine("Dictionary तत्व: " + dict.Count);
}
}
आउटपुट
Dictionary तत्व: 7