ContainsAll - Kalkwst/Risotto GitHub Wiki

Definition

Determines whether all of the elements of the target sequence exist in the source sequence, optionally using a custom comparer.

In this page

Overloads

Overload Description
ContainsAll(IEnumerable target) Determines whether target is a subset of source.
[ContainsAll(IEnumerable target, IEqualityComparer? comparer) Determines whether target is a subset of source, using a custom comparer

ContainsAll(IEnumerable target)

Determines whether all of the elements of the target sequence exist in the source sequence.

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

Type Parameters

TSource
The type of the elements of source.

Parameters

source IEnumerable <TSource>
The sequence to compare with target.

target IEnumerable <TSource>
The sequence to see if is a subset of source.

Returns

Boolean

true if target is a subset of source, false otherwise.

Exceptions

ArgumentNullException
source is null

Example

The following code example demonstrates how to use ContainsAll(IEnumerable target) to determine if target is a subset of source.

var odds = new int[]{1, 3, 5};
var one = new int[]{1};
var two = new int[]{2};

odds.ContainsAll(one);
//=> true

odds.ContainsAll(two);
//=> false

ContainsAll(IEnumerable target, IEqualityComparer? comparer)

Determines whether all of the elements of the target sequence exist in the source sequence, based on a custom equality comparer.

Type Parameters

TSource
The type of the elements of source.

Parameters

source IEnumerable <TSource>
The sequence to compare with target.

target IEnumerable <TSource>
The sequence to see if is a subset of source.

comparerIEqualityComparer
An equality comparer to compare values.

Returns

Boolean

true if target is a subset of source, false otherwise.

Exceptions

ArgumentNullException
source is null

-or-

comparer is null

Example

The following code example demonstrates how to use ContainsAll(IEnumerable target, IEqualityComparer? comparer) to determine if target is a subset of source.

var source = new string[]{ "a", "b", "C", "d", "e" };
var target = new string[]{"A", "c", "d"};

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