namespace ConsoleApplication13
{
    class Program
    {
      
        static void Main(string[] args)
        {
            new System.Threading.Thread(new System.Threading.ThreadStart(
                 () =>
                 {                 }
                )).Start();
            C c = new C();
            Console.Write(c["test2"].Name);  
        }
    }    class A
    {
        private string name;        public A(string names)
        {
            name = names;
        }
        public string Name
        {
            get{return name;}
        }
    }    class C
    {
        public Dictionary<string, A> test = new Dictionary<string, A>();        public C()
        {
            test.Add("test",new A("testValues"));
            test.Add("test2", new A("test2Values"));
        }        public A this[string key]
        {
            get
            {
                A value = test.Where(q => q.Key == key).Select(q => q.Value).FirstOrDefault();  //get all keys                return value;
            }
        }
    }

解决方案 »

  1.   

    你又不是LIST或ARRAY,那来的索引?
      

  2.   

    泛型和可以用下标访问毫无关系,你想这么访问,得定义一个索引器类似这样   
           public List<ClassA> lst;
           public ClassA this[int index]
            {
                get
                {                     
                   return lst[index];
                }
                set
                {
                  lst[index] = value;
               
                }
      

  3.   

    泛型类就不能同list一样?用索引访问?
      

  4.   

    你都没设索引
    class Class1<T>
    {
         public T this[int index]
         {
            get;set;
         }
    }
      

  5.   

    泛型类就不能同list一样?用索引访问?你非要cs[0].Name=""的话,得这样://Class1<string> cs = new Class1<string>();
    List<Class1<string>> cs = new List<Class1<string>>();
    cs.Add(new Class1<string>());
    cs[0].Name="";