C#에서 Clear() 메서드를 사용하여 해시 테이블을 지웁니다.
다음은 우리의 Hashtable입니다 -
Hashtable h = new Hashtable(); h.Add(1, "Amit"); h.Add(2, "Sachin"); h.Add(3, "Rahul");
명확한 방법을 사용하십시오.
h.Clear();
이제 Hashtable을 표시하려고 하면 Hashtable이 비어 있으므로 아무 것도 표시되지 않습니다.
예시
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable h = new Hashtable();
h.Add(1, "Amit");
h.Add(2, "Sachin");
h.Add(3, "Rahul");
Console.WriteLine("Keys and Values list:");
foreach (var key in h.Keys ) {
Console.WriteLine("Key = {0}, Value = {1}",key , h[key]);
}
// clear all key value pairs
Console.WriteLine("The Hashtable key and Value Pairs are empty now...");
h.Clear();
foreach (var key in h.Keys ) {
Console.WriteLine("Key = {0}, Value = {1}",key , h[key]);
}
}
} 출력
Keys and Values list: Key = 3, Value = Rahul Key = 2, Value = Sachin Key = 1, Value = Amit The Hashtable key and Value Pairs are empty now...