简体   繁体   English

为什么 Enumerable 不实现 IEnumerable?

[英]Why Enumerable does not implement IEnumerable?

I was looking to the metadata of the .Net framework trying to understand collections, and I saw that collections implement IEnumerable and IEnumerable<T> .我正在寻找试图理解集合的 .Net 框架的元数据,我看到集合实现了IEnumerableIEnumerable<T>

Then I looked at Enumerable and I found that it provides a set of static methods for querying objects that implement IEnumerable .然后我查看了Enumerable ,我发现它提供了一组静态方法来查询实现IEnumerable对象。

My question is, why Enumerable does not implement IEnumerable ?我的问题是,为什么Enumerable不实现IEnumerable

Or in other words, why it was named like that since it does not implement IEnumerable?或者换句话说,既然它没有实现 IEnumerable,为什么要这样命名?

Thanks in advance for your help!在此先感谢您的帮助!

Enumerable provides a set of static methods Enumerable 提供了一组静态方法

Enumerable is also a static class. Enumerable也是一个静态类。

what will happen if it does?如果这样做会发生什么?

The code would not compile - A static class cannot implement an interface.代码无法编译 - static类无法实现接口。 I agree by the naming convention you'd expect otherwise.我同意您所期望的命名约定。 But there you go.但是你去了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM