C#中Hashtable类的Count属性是什么?
若要查找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#中HashtableCount属性用法的完整示例。
示例
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
热门推荐
10 小红书生日祝福语简短
11 新年送老师简短祝福语
12 舞台上祝福语大全简短
13 工人生日祝福语简短
14 新年祝福语简短创意兄弟
15 租房明天搬家祝福语简短
16 收围巾的祝福语简短
17 祝福语勤奋大全简短英语
18 鼓励孩子小考祝福语简短