哈希表使用
using System.Collections;
namespace ConTest
{
class DataSeries
{
private Hashtable ownerDatas;
public double[] Datas { get; set; }
public double[]this[string name]
{
get
{
if (ownerDatas==null)
{
ownerDatas = new Hashtable();
}
return (double[])ownerDatas[name];
}
set
{
if (ownerDatas==null)
{
ownerDatas = new Hashtable();
}
ownerDatas[name] = value;
}
}
public DataSeries(int len)
{
this.Datas = new double[len];
}
public DataSeries()
{
this.Datas = new double[0] { };
}
}
}
Hashtable hasTable = new Hashtable();
hasTable.Add("gan", 23);
hasTable.Add("quan", 21);
hasTable.Add("fu", 24);
ArrayList keys = new ArrayList(hasTable.Keys);
keys.Sort();
foreach (var item in keys)
{
Console.WriteLine(item.ToString());
}
ArrayList values = new ArrayList(hasTable.Values);
values.Sort();
foreach (var item in values)
{
Console.WriteLine(item);
}