Method Consume
| Edit this page View SourceConsume<T>(IEnumerable<T>)
Completely consumes the given sequence.
Declaration
public static void Consume<T>(this IEnumerable<T> source)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | source | Source to consume. |
Type Parameters
Name | Description |
---|---|
T | Element type of the sequence. |
Remarks
The purpose of this method is to execute the operators for the provided IEnumerable<T>, in the event that the operators have side-effects.
This method executes immediately.
Examples
The following code example demonstrates consume a sequence using the Consume
operator.
var sequence = Enumerable.Range(1, 5)
.Do(i => Console.Write($"{i}, "));
// Consume the provided sequence
sequence.Consume();
// This code produces the following output:
// 1, 2, 3, 4, 5,
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|