【问题标题】:CollectionBase no IList implementation?CollectionBase 没有 IList 实现?
【发布时间】:2013-02-24 21:46:17
【问题描述】:

谁能向我解释为什么在抽象的CollectionBase 类中(在派生自IListSystem.Collections 中)它没有实现IList 成员?我认为这是强制性的。

【问题讨论】:

  • It 实现例如IList.Add, IList.Contains, IList.IndexOf, IList.Insert, IList.IsFixedSize, IList.IsReadOnly, IList.Item, IList.Remove。那么问题是什么?
  • 这正是我要搜索的内容,但是当我检查 CollectionBase 定义时,我看不到任何 IList 实现...
  • 您在哪里寻找CollectionBase定义?我总是先看 MSDN:msdn.microsoft.com/en-us/library/…
  • 我确实使用 F12 或上下文菜单 > Visual Studio 2010 .NET 4.0 检查定义。你就在 msdn 上我可以看到我缺少的显式实现我现在很困惑为什么我在 Collection 名称空间中看不到它们?

标签: c# .net ilist members collectionbase


【解决方案1】:

它实现了IListexplicitly,因此您需要将CollectionBase 实例转换为IList 才能访问这些成员。

IList list = (IList)collectionBase;
list.Add(...);

【讨论】:

  • 当我检查 CollectionBase 的定义时,我发现它们都不是应该在 CollectionBase 中明确定义的?
  • @Mikatsu - 我不确定你从哪里得到定义,但如果你查看here 并向下滚动到“显式接口实现”,你会看到它明确实现了@ 987654327@ 和 ICollection.
  • 我已经在开始帖子中添加了一张图片,为什么它与 msdn 不同?我在 Visual Studio 中使用 F12。
  • @Mikatsu - 显式实现的接口方法是实现类私有的,Visual Studio 似乎只在定义中显示公共和受保护的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 2010-09-12
  • 2010-10-15
  • 1970-01-01
  • 2011-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多