【问题标题】:Why Enumerable does not implement IEnumerable?为什么 Enumerable 不实现 IEnumerable?
【发布时间】:2020-05-18 17:13:54
【问题描述】:

我正在查看 .Net 框架的元数据,试图理解集合,我看到集合实现了 IEnumerableIEnumerable<T>

然后我查看了Enumerable,发现它提供了一组静态方法,用于查询实现IEnumerable 的对象。

我的问题是,为什么Enumerable 没有实现IEnumerable

或者换句话说,既然它没有实现IEnumerable,为什么要这样命名?

提前感谢您的帮助!

【问题讨论】:

  • 您希望实现返回什么?

标签: c# collections ienumerable enumerable


【解决方案1】:

Enumerable 提供了一组静态方法

Enumerable 也是一个静态类。

如果发生了会发生什么?

代码无法编译 - static 类无法实现接口。我同意您所期望的命名约定。但是你去吧。

【讨论】:

  • 感谢您的回答!是的,没错,命名让我感到困惑。
猜你喜欢
  • 2023-04-07
  • 2011-04-04
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
  • 2012-04-01
  • 2010-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多