当前位置:编程学习 > C#/ASP.NET >>

集合>哈希表类Hashtable和SortedList排序列表类

 集合>哈希表类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(20, 0.8f);
            //实例化一个SortedList。
            SortedList sl = new SortedList();
            sl.Add("键一", "键值一");
            sl.Add("键二", "键值二");
            sl.Add("键三", "键值三");
            //传入实现了IDictionary接口的参数创建哈希表。
            Hashtable ht3 = new Hashtable(sl);
        }
    }
}

 

集合>哈希表类Hashtable>获取哈希表值

\代码
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,