集合>哈希表类Hashtable

Hashtable一种键值对的集合 ,哈希表内部的排列是无序的,而且哈希表没有提供排序方法。

 

集合>哈希表类Hashtable>构造普通哈希表

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
//使用所有默认值构建哈希表实例
            Hashtable ht = new Hashtable();
            
//指定哈希表实例的初始容量为20个元素
            Hashtable ht1 = new Hashtable(20);
            
//指定初始容量为20个元素,加载因子为0.8的哈希表实例,加载因子大,哈希表自动扩展容量也大。
            Hashtable ht2 = new Hashtable(200.8f);
            
//实例化一个SortedList。
            SortedList sl = new SortedList();
            sl.Add(
"键一""键值一");
            sl.Add(
"键二""键值二");
            sl.Add(
"键三""键值三");
            
//传入实现了IDictionary接口的参数创建哈希表。
            Hashtable ht3 = new Hashtable(sl);
        }
    }
}

相关文章: