Method Exclude
| Edit this page View SourceExclude<T>(IEnumerable<T>, int, int)
Excludes a contiguous number of elements from a sequence starting at a given index.
Declaration
public static IEnumerable<T> Exclude<T>(this IEnumerable<T> sequence, int startIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | sequence | The sequence to exclude elements from |
int | startIndex | The zero-based index at which to begin excluding elements |
int | count | The number of elements to exclude |
Returns
Type | Description |
---|---|
IEnumerable<T> | A sequence that excludes the specified portion of elements |
Type Parameters
Name | Description |
---|---|
T | The type of the elements of the sequence |
Remarks
This method uses deferred execution and streams its results.
Examples
The following code example demonstrates how to exclude a contiguous set of elements from a sequence using Exclude
.
var sequence = Enumerable.Range(1, 10);
// Execute an action for each element
var result = sequence
.Exclude(3, 5);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [1, 2, 3, 9, 10]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
Exclude<T>(IEnumerable<T>, Range)
Excludes a contiguous number of elements from a sequence starting at a given index.
Declaration
public static IEnumerable<T> Exclude<T>(this IEnumerable<T> sequence, Range range)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | sequence | The sequence to exclude elements from |
Range | range | The zero-based index at which to begin excluding elements |
Returns
Type | Description |
---|---|
IEnumerable<T> | A sequence that excludes the specified portion of elements |
Type Parameters
Name | Description |
---|---|
T | The type of the elements of the sequence |
Remarks
This method uses deferred execution and streams its results.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|