ContainsAny - Kalkwst/Risotto GitHub Wiki

Definition

Determines whether the first sequence contains any of the elements of the second sequence, optionally using a custom equality comparer.

In this page

Overloads

Overload Description
ContainsAny(IEnumerable target) Determines whether source sequence contains any of the elements of target sequence.
ContainsAny(IEnumerable target, IEqualityComparer? comparer) Determines whether source sequence contains any of the elements of target sequence using the provided comparer

ContainsAny(IEnumerable target)

Determines whether source sequence contains any of the elements of target sequence using the default comparer.

public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> target);

Type Parameters

TSource
The type of the elements of source

Parameters

source IEnumerable <TSource>
A sequence to check if contains any element of the target.

target IEnumerable <TSource>
A sequence to check if any of its elements are contained in source.

Returns

Boolean

true source contains any element of the target sequence, false otherwise.

Exceptions

ArgumentNullException
source is null

-or-

target is null

Example

The following code example demonstrates how to use ContainsAny(IEnumerable target) to determine if source contains any elements of the target sequence.

var source = new int[]{ 1, 2, 3, 4, 5 };
var target = new int[]{ 1, 2, 6 };

source.ContainsAny(target);
//=> true

ContainsAny(IEnumerable target, IEqualityComparer? comparer)

Determines whether source sequence contains any of the elements of target sequence using an optional custom equality comparer.

public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> target, IEqualityComparer<TSource>? comparer);

Type Parameters

TSource
The type of the elements of source

Parameters

source IEnumerable <TSource>
A sequence to check if contains any element of the target.

target IEnumerable <TSource>
A sequence to check if any of its elements are contained in source.

comparerIEqualityComparer
An equality comparer to compare values.

Returns

Boolean

true source contains any element of the target sequence, false otherwise.

Exceptions

ArgumentNullException
source is null

-or-

target is null

Example

The following code example demonstrates how to use ContainsAny(IEnumerable target) to determine if source contains any elements of the target sequence.

var source = new string[]{ "a", "b", "c" };
var target = new string[]{ "a", "B", "Ducks" };

source.ContainsAny(target, StringComparer.OrdinalIgnoreCase);
//=> true
⚠️ **GitHub.com Fallback** ⚠️