public abstract class CollectionBase : IList, ICollection,IEnumerable
msdn的example
public class Int16Collection : CollectionBase  {....}
我们知道CollectionBase有个属性List返回IList接口,通常我们用它
但CollectionBase本身应该还是实现了IList的方法了吧,如Add,Clear

解决方案 »

  1.   

    IList 的成员都是显式实现的
      

  2.   

    CollectionBase本身应该还是实现了IList的方法了吧,如Add,Clear
    ==========================================
    ms-help://MS.MSDNQTR.2003FEB.2052/csspec/html/vclrfcsharpspec_13_4_1.htm
      

  3.   

    如果你在仔细看看MSDN
    你会发现MS显示显示了一些接口成员
    如IList.Add()
    所以CollectionBase没有Add这个方法当显式实现某成员时,不能通过类实例访问该成员,而只能通过该接口的实例访问该成员。
    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/csref/html/vcwlkexplicitinterfaceimplementationtutorial.asp
      

  4.   

    chengbo1983,
       我看了一下显式接口,按你上述的意思,CollectionBase 是为如下所写
    public abstract class CollectionBase : IList, ICollection, IEnumerable
        {
    ...
    void IList.Clear() {...}}
    理解有误否?
      

  5.   

    to 但CollectionBase本身应该还是实现了IList的方法了吧,如Add,Clear这是肯定的,接口只定义方法和属性,并没有实现,当某个类继承于接口,必须实现接口所定义的方法和属性。
      

  6.   

    如果你用Reflector这个软件反编译一下mscorlib
    你会看见CollectionBase如下:[Serializable]
    public abstract class CollectionBase : IList, ICollection, IEnumerable
    {
          // Methods
          protected CollectionBase();
          public void Clear();
          public IEnumerator GetEnumerator();
          protected virtual void OnClear();
          protected virtual void OnClearComplete();
          protected virtual void OnInsert(int index, object value);
          protected virtual void OnInsertComplete(int index, object value);
          protected virtual void OnRemove(int index, object value);
          protected virtual void OnRemoveComplete(int index, object value);
          protected virtual void OnSet(int index, object oldValue, object newValue);
          protected virtual void OnSetComplete(int index, object oldValue, object newValue);
          protected virtual void OnValidate(object value);
          public void RemoveAt(int index);
          void ICollection.CopyTo(Array array, int index);
          int IList.Add(object value); //***** 注意这里 ******
          bool IList.Contains(object value);
          int IList.IndexOf(object value);
          void IList.Insert(int index, object value);
          void IList.Remove(object value);      // Properties
          public int Count { get; }
          protected ArrayList InnerList { get; }
          protected IList List { get; }
          bool ICollection.IsSynchronized { get; }
          object ICollection.SyncRoot { get; }
          bool IList.IsFixedSize { get; }
          bool IList.IsReadOnly { get; }
          object IList.this[int index] { get; set; }      // Fields
          private ArrayList list;
    }
      

  7.   

    我注释的那里就是接口的显示实现,所以你不能用类实例(CollectionBase及子类实例)访问该方法,而只能通过该接口的实例(IList)访问该方法。