//[1]Hashtable 개체
Hashtable ht1 = new Hashtable();
Hashtable ht2 = new Hashtable();
//[2]할당
ht1.Add("a", "aa");
ht1.Add("b", "bb");
ht1.Add("c", "cc");
ht1.Add("d", "dd");
ht1.Add("e", "ee");
ht2.Add(0, "0");
ht2.Add(1, "1");
ht2.Add(2, "2");
//[3]DictionaryEntry 를 사용
foreach (DictionaryEntry de in ht1)
{
Response.Write(String.Format("key : {0}, value : {1}
", de.Key, de.Value));
}
Response.Write("
");
//[4]ICollection 를 사용 ; 값만
ICollection ic = ht1.Values;
foreach (string str in ic)
{
Response.Write(String.Format("values : {0}
", str));
}
Response.Write("
");
//[5]ICollection 를 사용 ; 키만
ICollection ic2 = ht1.Keys;
foreach (string str2 in ic2)
{
Response.Write(String.Format("keys : {0}
", str2));
}
Response.Write("
");
//[6]인덱스
for (int i = 0; i < ht2.Count; i++)
{
Response.Write(String.Format("index : {0}, value: {1}", i.ToString(), ht2[i]));
Response.Write("
");
}
Response.Write("
");
//[7]IEnumerator 사용 ; 값만
IEnumerator ie1 = ht1.Values.GetEnumerator();
while (ie1.MoveNext())
{
Response.Write(String.Format("value : {0}
", ie1.Current.ToString()));
}
Response.Write("
");
//[8]IEnumerator 사용 ; 키만
IEnumerator ie2 = ht1.Keys.GetEnumerator();
while (ie2.MoveNext())
{
Response.Write(String.Format("key : {0}
", ie2.Current.ToString()));
}