Method Where
| Edit this page View SourceWhere<TSource>(IEnumerable<TSource>, IEnumerable<bool>)
Filters a sequence of values based on an enumeration of boolean values
Declaration
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, IEnumerable<bool> filter)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TSource> | source | An IEnumerable<T> to filter. |
IEnumerable<bool> | filter | An IEnumerable<T> of boolean values identifying which elements of |
Returns
Type | Description |
---|---|
IEnumerable<TSource> | An IEnumerable<T> that contains elements from the input sequence where the matching value in
|
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of source. |
Examples
The following code example demonstrates how to create filter a sequence with matching bool
values using Where
.
var sequence = Enumerable.Range(1, 5);
// Filter a sequence based on a matching sequence of bools
var result = sequence
.Where([true, false, true, true, false]);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [1, 3, 4]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|