数组取元素只能用数组对象[索引整数];根据字符串去取元素是一种c#中默认属性的用法,看看文档System.Collections.Specialized的类NameValueCollection的属性Item(String),发现这个属性是这样定义的public string this[string name] {get; set;}

解决方案 »

  1.   

    NameValueCollection nvc = new NameValueCollection();
    nvc.Add("first",null);
    nvc.Add("second","how");
    nvc.Add("Second","thank");
    Console.WriteLine("nvc[second]:"+nvc["second"]);//对象[字符串]
    for(int i=0;i<nvc.Count;i++)
    Console.WriteLine("nvc[i]:"+nvc[i]);//对象[整型]还有对象[对象]这样取元素的,就象Hashtable的默认索引器。
      

  2.   

    更多的文档请参考:
    ms-help://MS.NETFrameworkSDKv1.1.CHS/csref/html/vcwlkIndexersTutorial.htm
    (别的版本请截取csref/html/vcwlkIndexersTutorial.htm)
      

  3.   

    明白了,重载了两个索引器,一个参数为 int,一个参数为string.
    感谢: xixigongzhu(夕夕公主)