David Klempfner
David Klempfner

Reputation: 9940

ICollection acting as IEnumerable

I am accessing the Keys of an OrderedDictionary:

enter image description here

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?

Upvotes: 0

Views: 152

Answers (1)

user47589
user47589

Reputation:

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.

Upvotes: 3

Related Questions