c# hashtable 怎么理解

来源:百度知道 编辑:UC知道 时间:2024/06/24 14:16:16
Hashtable hash_field=new Hashtable();
hash_field =(Hashtable)Session["WF_EFormFields"];
if (hash_field!=null)
{
hash_field["group"]="";
hash_field["txtxzry"]="";

其实hastable就像是一个特殊的数组,它有一个类似主键的唯一编号(类似数组[]中的数字,这个键值是你随便写的),和这个唯一编号又对应一个值value(值的数据类型是不受限制的)
下面是一个适用hashtable类的例子:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace 练习
{
public class name
{

Hashtable hs = new Hashtable();
public void hashtable()
{
hs.Add("001","周杰伦87992352");
hs.Add("002","张娜拉87993952");
hs.Add("003","刘德华87993723");
foreach (DictionaryEntry dr in hs)//通过DictionaryEntry遍历hashtable
{
string key = (string)dr.Key;
string value = (string)dr.Value;
Console.WriteLine("编号为"+key+" 的号码为:");
}
hs.Remove("003");//移除键值为003的记录
if (!hs.Contains