Difference - Kalkwst/Risotto GitHub Wiki

Definition

Calculates the difference between two arrays, without filtering duplicate values and using an optional custom comparer.

In this page

Overloads

Overload Description
Difference(IEnumerable target) Calculates the difference between two arrays, without filtering duplicate values.
Difference(IEnumerable target, IEqualityComparer comparer) Calculates the difference between two arrays, without filtering duplicate values, using a custom comparer.

Difference(IEnumerable target)

Calculates the difference between two arrays, without filtering duplicate values.

public static IEnumerable<T> Difference<T>(this IEnumerable<T> source, IEnumerable<T> target);

Type Parameters

T
The type of the elements of the sequences.

Parameters

source IEnumerable <TSource>
The source sequence.

target IEnumerable <TSource>
The target sequence.

Returns

IEnumerable<IEnumerable<TSource>>
A sequence containing all the elements that exist in the source sequence, and not the target sequence, without filtering duplicates.

Exceptions

ArgumentNullException
source is null

Example

The following code example demonstrates how to use Difference(IEnumerable target) to find all elements existing in the source sequence, and not on the target sequence.

int[] array = new int[] { 1, 2, 3, 4, 5 };
int[] array2 = new int[] { 1, 2, 3 };

array.Difference(array2);
//=> [ 4, 5 ]

Difference(IEnumerable target, IEqualityComparer comparer)

Calculates the difference between two arrays, without filtering duplicate values, using a custom equality comparer.

public static IEnumerable<T> Difference<T>(this IEnumerable<T> source, IEnumerable<T> target, IEqualityComparer<T> comparer);

Type Parameters

T
The type of the elements of the sequences.

Parameters

source IEnumerable <TSource>
The source sequence.

target IEnumerable <TSource>
The target sequence.

comparerIEqualityComparer<TSource>
The custom equality comparer to use for the comparison.

Returns

IEnumerable<IEnumerable<TSource>>
A sequence containing all the elements that exist in the source sequence, and not the target sequence, without filtering duplicates.

Exceptions

ArgumentNullException
source is null

-or-

comparer is null

Example

The following code example demonstrates how to use Difference(IEnumerable target) to find all elements existing in the source sequence, and not on the target sequence, using a custom equality comparer.

string[] array = new string[] { "a", "b", "C" };
string[] array2 = new string[] { "a", "c" };

array.Difference(array2, StringCommparer.OrdinalIgnoreCase);
//=> b
⚠️ **GitHub.com Fallback** ⚠️