Does AsEnumerable() cache all result (LINQ)

后端 未结 2 1323
遇见更好的自我
遇见更好的自我 2021-01-28 05:53

When we call a query operator on a sequence, a sequence-specific operator gets called.
I mean if i call Where<>() operator on IEnumerable<>

2条回答
  •  借酒劲吻你
    2021-01-28 06:35

    IQueryable extends IEnumerable, so the AsEnumerable is redundant. However, if you use it, AsEnumerable is not going to greedily load the collection (that would be a very annoying "feature"). Clearly, Reverse will need the whole thing. Mono implements Enumerable.Reverse using a List and a simple iterator-generator that yields in reverse.

    I believe the only real purpose of AsEnumerable is to force the use of IEnumerable explicit interface implementations.

提交回复
热议问题