是键值对吗?不允许一对多?可以通过键找值,反过来呢?这容器里的对象不要求同一类型吧?给他添加一个元素不一定要 Add 吧?直接给个索引赋值就行了吧?
using System;
using System.Collections;
class IndexClass
{    Hashtable aa = new Hashtable();    public string this[int index]
    {
        get
        {            return aa[index].ToString();
        }
        set
        {            //aa[index] = value;            //直接赋值
            aa.Add(index, value);
        }
    }    public int this[ string index]
    {
        get
        {
            return (int)aa[index];
        }
        set
        {
           // aa[index] = value;
            aa.Add(index, value);        }
    }
}class Test_3
{
    static void Main()
    {
        IndexClass ic = new IndexClass();        ic["1"] = 2;
        ic[3] = "1";
        Console.WriteLine(ic["1"]);
        Console.WriteLine(ic[3]);
    }
}

解决方案 »

  1.   

    1.是键值;
    2.不允许;
    3.可以通过键找值,反过来不行;
    4.不要求同一类型,如果用泛型的话,就要同一类型;
    5.一定要 Add;
    6.不行
      

  2.   

    拜托,看什么数据结构?我想看源码,很怀疑是不是有什么机制转换的。 F11 看不了。为什么可以直接赋值 aa[index] = value;可以不用   aa.Add(index, value);
      

  3.   

    为什么可以直接赋值 aa[index] = value;可以不用   aa.Add(index, value);