关于C# IList接口,有些迷惑的地方。

lazyfish 2006-04-30 03:21:52
MSDN上描述:

public interface IList : ICollection, IEnumerable
而其中继承的一个接口ICollection却是继承了IEnumerable
public interface ICollection : IEnumerable

问题:
为什么不直接这样,还要加上IEnumerable?迷惑中……
public interface IList : ICollection
...全文
958 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
deadshot123 2006-04-30
  • 打赏
  • 举报
回复
thanks
zhongkeruanjian 2006-04-30
  • 打赏
  • 举报
回复
http://www.cnblogs.com/allenlooplee/archive/2004/11/16/64394.html

这是个很权威的解答了,仅仅为了提高代码的可读性。
lazyfish 2006-04-30
  • 打赏
  • 举报
回复
楼上的,不是要你搞个什么具体类。看清楚我的问题。
naturalth 2006-04-30
  • 打赏
  • 举报
回复
class aa : IList, IEnumerable
{
#region IList 成员

public int Add(object value)
{
throw new Exception("The method or operation is not implemented.");
}

public void Clear()
{
throw new Exception("The method or operation is not implemented.");
}

public bool Contains(object value)
{
throw new Exception("The method or operation is not implemented.");
}

public int IndexOf(object value)
{
throw new Exception("The method or operation is not implemented.");
}

public void Insert(int index, object value)
{
throw new Exception("The method or operation is not implemented.");
}

public bool IsFixedSize
{
get { throw new Exception("The method or operation is not implemented."); }
}

public bool IsReadOnly
{
get { throw new Exception("The method or operation is not implemented."); }
}

public void Remove(object value)
{
throw new Exception("The method or operation is not implemented.");
}

public void RemoveAt(int index)
{
throw new Exception("The method or operation is not implemented.");
}

public object this[int index]
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}

#endregion

#region ICollection 成员

public void CopyTo(Array array, int index)
{
throw new Exception("The method or operation is not implemented.");
}

public int Count
{
get { throw new Exception("The method or operation is not implemented."); }
}

public bool IsSynchronized
{
get { throw new Exception("The method or operation is not implemented."); }
}

public object SyncRoot
{
get { throw new Exception("The method or operation is not implemented."); }
}

#endregion

#region IEnumerable 成员

public IEnumerator GetEnumerator()
{
throw new Exception("The method or operation is not implemented.");
}

#endregion
}
这个是实现这两个接口的具体类
gnhao 2006-04-30
  • 打赏
  • 举报
回复
我想是有些东西可能没继承过来,吧。或许重写了List里要用到的IEnumerable里的东西。。。
人人认为啊,别B4
lazyfish 2006-04-30
  • 打赏
  • 举报
回复
郁闷,没有人知道原因吗?
lazyfish 2006-04-30
  • 打赏
  • 举报
回复
自己顶一个。
deadshot123 2006-04-30
  • 打赏
  • 举报
回复
翻了下MSDN
变的跟楼主一样困惑:(
deadshot123 2006-04-30
  • 打赏
  • 举报
回复
猜想、猜想。。。
ICollection实现了IEnumerable中一部分方法 有一部分没有实现 直接以空方法替代
那么IList可以多实现一些方法 比如那些空方法

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧