类ArrayList为什么要继承接口IEnumerable接?
c#吧
全部回复
仅看楼主
level 6
lei_LINGER 楼主
1。 接口public interface ICollection的基类型是public interface IEnumerable,那么如果一个类继承了接口ICollection,那么它要实现2个接口ICollection和 IEnumerable的全部成员,这句话没错吧?
2。 如果第一句话没错,那MS为什么在定义类ArrayList时这样写呢?:public class ArrayList : IList, ICollection, IEnumerable, ICloneable
在定义类 ArrayList时为什么要把 IEnumerable也写上去呢?有特殊的原因吗?
2015年06月09日 08点06分 1
level 12
我只是觉得= =可以遍历
2015年06月09日 08点06分 2
ICollection已经继承了 IEnumerable的唯一的一个函数,ArrayList继承了 ICollection接口,必然要实现IEnumberable的函数,所以我认为不需要写上IEnumerable,可是MS为什么要写上呢?我觉得没必要,不知道MS为何要这样做
2015年06月09日 09点06分
@lei_LINGER 这就不知道了,可能只是为了楼下说的,显示继承
2015年06月10日 01点06分
回复正怒月神:也许吧
2015年06月10日 01点06分
level 11
提高可读性 不用纠结 就这样
2015年06月09日 09点06分 3
level 11
显式继承,好看
2015年06月09日 11点06分 4
level 8
提升性能
2015年06月10日 10点06分 5
level 8
提升性能
2015年06月10日 10点06分 6
level 11
第一眼看过去就知道能用ienumerable接口的方法
2015年06月10日 14点06分 8
1