Open sandboxFocus

Method Cache

Cache<T>(IEnumerable<T>)

Caches an enumerable sequence as a read-only list. If the sequence is already a list, it is returned as-is; otherwise, the sequence is enumerated and cached.

Declaration
public static IReadOnlyList<T> Cache<T>(this IEnumerable<T> items)
Parameters
Type Name Description
IEnumerable<T> items

The sequence to cache.

Returns
Type Description
IReadOnlyList<T>

A read-only list containing the items from items.

Type Parameters
Name Description
T

The type of items in the sequence.