Hashtable은 사전보다 느립니다. 강력한 형식의 컬렉션의 경우 Dictionary 컬렉션이 더 빠릅니다.
해시테이블
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
사전
사전은 C#의 키와 값의 모음입니다. Dictionary
예
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 elements: "+dict.Count);
}
} 출력
Dictionary elements: 7