public interface IEnumeratorpublic interface ICollection : IEnumeratorpublic interface IList : ICollectionpubilc class ArrayList : IList,ICollection,IEnumerator为何不是public class ArrayList : IList
IList接口不是已经继承了上面的两个接口了吗?
而且这样为何不会出现接口重定义,IList已经包含了ICollection中的接口了.
IList接口不是已经继承了上面的两个接口了吗?
而且这样为何不会出现接口重定义,IList已经包含了ICollection中的接口了.
那样还不如不要把IList继承ICollection有点不理解
public interface IEnumerator
{
object Current { get; };
bool MoveNext ();
void Reset ();
}public interface ICollection : IEnumerator //ICollection并没有实现IEnumerator中的成员
{
int Count { get; };
bool IsSynchronized { get; };
object SyncRoot { get; };
void CopyTo (Array array,int index);
}public interface IList : ICollection, IEnumerable //IList并没有实现ICollection和IEnerable中的成员
{
bool IsFixedSize { get; };
bool IsReadOnly { get; };
object this [int index] { get; set; };
int Add (object value);
void Clear ();
bool Contains (Object value);
int IndexOf (Object value);
void Insert (int index,Object value);
void Remove (Object value);
void RemoveAt (int index);
}
那么IList只需继承ICollection便可,为何又要继承IEnumerator
希望能解决下
这一贴,pubilc class ArrayList : IList,ICollection,IEnumerator
其实完全可以使用public class ArrayList : IList来替代.
因为IList本身已经继承了ICollection而ICollection又继承了IEnumerator.所以传递性.pubilc class ArrayList : IList,ICollection,IEnumerator
这种定义方法有两种好处:
一,象上面一个朋友说的,提高代码可读性,
二,也是比较重要的,可以显示的实现接口.
如
public class ArrayList : IList,ICollection,IEnumerator
{
IList.xxx(){}
ICollection.xxxxx(){}
IEnumerator.xxxxxxx(){}
}有点儿明白,呆会再结贴,相信有很多人像我一样犯迷糊.
如果是IList.GetEnumerator() 那样的话代码并不是很友好..