EnumerableUtility.AsReadOnlyList<T> method

Represents the sequence as an IReadOnlyList.

public static IReadOnlyList<T> AsReadOnlyList<T>(this IEnumerable<T> source)
parameter description
T The type of items in the collection.
source The sequence.

Return Value

An IReadOnlyList containing the items in the sequence.

Remarks

If the sequence is an IReadOnlyList, it is returned directly. If it is an IList, an adapter is created to wrap it. Otherwise, the sequence is copied into a List and then wrapped in a ReadOnlyCollection. This method is useful for forcing evaluation of a potentially lazy sequence while retaining reasonable performance for sequences that are already an IReadOnlyList or IList.

See Also