ICollection充当IEnumerable [英] ICollection acting as IEnumerable

查看:187
本文介绍了ICollection充当IEnumerable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问OrderedDictionaryKeys:

为什么这么说?:

扩展结果视图将枚举IEnumerable

Expanding the Results View will enumerate the IEnumerable

我认为已经列举了比IEnumerable更具体的内容(例如ICollectionIList等)?

I thought anything more concrete than an IEnumerable (eg ICollection, IList etc) are already enumerated?

推荐答案

List<T>同时实现IList<T>IEnumerable<T>.从逻辑上讲,它既不能被枚举,也不能被枚举.这些界面仅定义了一个契约,您可以通过该契约与对象进行交互.

List<T> implements both IList<T> and IEnumerable<T>. Logically, it cannot be both already enumerated and not already enumerated. The interfaces only define a contract through which you can interact with the object.

重要的是实现接口的基础类型. LINQ表达式树使用延迟执行,其对象结构表示未决的LINQ操作.实现问题中的接口的基础类型知道它是否表示这样的延迟操作.

What matters is the underlying type implementing the interface. LINQ expression trees use deferred execution, with an object structure representing the pending LINQ operation(s). That underlying type, which implements the interfaces in the question, knows whether it represents such a deferred operation.

在这种情况下,基础对象确实使用了延迟执行,因此VS会提示您.

In this case, the underlying object does use deferred execution, so VS prompts you.

这篇关于ICollection充当IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆