Hashtable 클래스의 요소 수를 찾으려면 Count 속성을 사용하십시오. 먼저 Hashtable 클래스를 요소로 설정하십시오 -
Hashtable ht = new Hashtable();
ht.Add("One", "Tom");
ht.Add("Two", "Jack");
ht.Add("Three", "Peter");
ht.Add("Four", "Russel");
ht.Add("Five", "Brad");
ht.Add("Six", "Bradley");
ht.Add("Seven", "Steve");
ht.Add("Eight", "David"); 이제 Count 속성을 사용하여 요소 수를 계산하십시오 -
ht.Count
다음은 C#에서 Hashtable Count 속성의 사용법을 배우기 위한 전체 예제입니다.
예
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
Hashtable ht = new Hashtable();
ht.Add("One", "Tom");
ht.Add("Two", "Jack");
ht.Add("Three", "Peter");
ht.Add("Four", "Russel");
ht.Add("Five", "Brad");
ht.Add("Six", "Bradley");
ht.Add("Seven", "Steve");
ht.Add("Eight", "David");
Console.WriteLine("Count = " + ht.Count);
Console.ReadKey();
}
}
} 출력
Count = 8