ICollection<string> list = aa.getnames();
            MessageBox.Show(list.Count.ToString());// “5”
aa返回了个  ICollection<string> ,里面有5个,但是怎么才能访问这5个呢?
谢谢了。
还有就是怎么才能转成 List<string> ?

解决方案 »

  1.   

    List就是实现了ICollection接口,可以直接用foreach枚举。
      

  2.   

    ICollection<string> list = aa.getnames();
             foreach(string l in list)
              {
                  //l 就是里面的项,可以进行操作
              }
      

  3.   

    这种问题msdn最专业
    ICollection<T> Interface英文解释
    中文解释
      

  4.   

    //
            // Summary:
            //     Creates a System.Collections.Generic.List<T> from an System.Collections.Generic.IEnumerable<T>.
            //
            // Parameters:
            //   source:
            //     The System.Collections.Generic.IEnumerable<T> to create a System.Collections.Generic.List<T>
            //     from.
            //
            // Type parameters:
            //   TSource:
            //     The type of the elements of source.
            //
            // Returns:
            //     A System.Collections.Generic.List<T> that contains elements from the input
            //     sequence.
            //
            // Exceptions:
            //   System.ArgumentNullException:
            //     source is null.
            public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source);