哈希表使用

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);
           }

 

posted @ 2013-05-22 21:08  Predator  阅读(175)  评论(0编辑  收藏  举报