public abstract class CollectionBase : IList, ICollection,IEnumerable
msdn的example
public class Int16Collection : CollectionBase {....}
我们知道CollectionBase有个属性List返回IList接口,通常我们用它
但CollectionBase本身应该还是实现了IList的方法了吧,如Add,Clear
msdn的example
public class Int16Collection : CollectionBase {....}
我们知道CollectionBase有个属性List返回IList接口,通常我们用它
但CollectionBase本身应该还是实现了IList的方法了吧,如Add,Clear
==========================================
ms-help://MS.MSDNQTR.2003FEB.2052/csspec/html/vclrfcsharpspec_13_4_1.htm
你会发现MS显示显示了一些接口成员
如IList.Add()
所以CollectionBase没有Add这个方法当显式实现某成员时,不能通过类实例访问该成员,而只能通过该接口的实例访问该成员。
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/csref/html/vcwlkexplicitinterfaceimplementationtutorial.asp
我看了一下显式接口,按你上述的意思,CollectionBase 是为如下所写
public abstract class CollectionBase : IList, ICollection, IEnumerable
{
...
void IList.Clear() {...}}
理解有误否?
你会看见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;
}