Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once

后端 未结 3 504
我在风中等你
我在风中等你 2020-12-08 08:17

Provided items is the result of q LINQ expression:

var items = from item in ItemsSource.RetrieveItems()
            where ...

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 08:37

    Take a look at the Reactive Extentsions library - there is a MemoizeAll() extension which will cache the items in your IEnumerable once they're accessed, and store them for future accesses.

    See this blog post by Bart De Smet for a good read on MemoizeAll and other Rx methods.

    Edit: This is actually found in the separate Interactive Extensions package now - available from NuGet or Microsoft Download.

提交回复
热议问题