C#遍历哈希表
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace an
{
public class CRYSTAL_INFO
{
public static Hashtable INFO = new Hashtable();
static CRYSTAL_INFO()
{
Hashtable hs1 = new Hashtable();
hs1["item_index"] = 12000;
hs1["crystal_type"] = 102;
hs1["sum_count"] = 1000;
hs1["sale_type"] = 1;
INFO[12000] = hs1;
Hashtable hs2 = new Hashtable();
hs2["item_index"] = 12005;
hs2["min_price"] = 200;
hs2["server_day"] = 20;
hs2["sale_type"] = 2;
INFO[12005] = hs2;
}
}
public class ca
{
static void Main(string[] args)
{
Hashtable table = CRYSTAL_INFO.INFO;
//遍历表的key
foreach (int key in table.Keys)
{
//Console.WriteLine(key);
}
//遍历表的值
foreach (Hashtable obj in table.Values)
{
Console.WriteLine(obj);
Console.WriteLine("-----------------------------------------");
//遍历key
foreach (Object v in obj.Keys)
{
Console.WriteLine(v);
}
Console.WriteLine("-----------------------------------------");
//遍历值
foreach (Object v in obj.Values)
{
Console.WriteLine(v);
}
Console.WriteLine("-----------------------------------------");
}
// foreach (Hashtable obj in menulist.Values)
// DictionaryEntry en = (DictionaryEntry)obj;
// Console.WriteLine(en.Key);
// Console.WriteLine(en.Value);
//Console.WriteLine(key);
//Console.WriteLine(obj.Values);
// Console.WriteLine(obj);
Console.ReadKey();
}
}
}