ICollection acting as IEnumerable

半世苍凉 提交于 2019-12-24 20:08:35

问题


I am accessing the Keys of an OrderedDictionary:

Why does it say this?:

Expanding the Results View will enumerate the IEnumerable

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


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/59313510/icollection-acting-as-ienumerable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!