在HashTable集合类中,它将项目存储为键值对。
在它中,表的每个项目都是唯一标识的键,密钥应该是唯一的,值可以相同或者复制。
Hashtable将密钥和值对存储为能够存储任何类型的物体类型,无论是字符串,整数还是长等,都可以使用键和对属性从Hashtable中检索密钥和值对的集合。
通过字串字典类,我们可以一次获取键+值对。
C# HashTable类示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication13 { class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add(1,"Honey"); ht.Add(2, "Aman"); ht.Add(3, "Rahul"); ht.Add(4, "Swati"); ht.Add(5, "Kirti"); Console.WriteLine(ht[2].ToString()); foreach (DictionaryEntry de in ht) { Console.WriteLine("Key is:"+de.Key.ToString()+"value is:"+de.Value.ToString()); } Console.ReadLine(); } } }
日期:2020-04-11 22:50:32 来源:oir作者:oir