Difference - Kalkwst/Risotto GitHub Wiki
Calculates the difference between two arrays, without filtering duplicate values and using an optional custom comparer
.
In this page
- Definition
- Overloads
- Difference(IEnumerable target)
- Difference(IEnumerable target, IEqualityComparer comparer)
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 . |
Calculates the difference between two arrays, without filtering duplicate values.
public static IEnumerable<T> Difference<T>(this IEnumerable<T> source, IEnumerable<T> target);
T
The type of the elements of the sequences.
source
IEnumerable <TSource>
The source sequence.
target
IEnumerable <TSource>
The target sequence.
IEnumerable<IEnumerable<TSource>>
A sequence containing all the elements that exist in the source
sequence, and not the target
sequence, without filtering duplicates.
ArgumentNullException
source
is null
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 ]
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);
T
The type of the elements of the sequences.
source
IEnumerable <TSource>
The source sequence.
target
IEnumerable <TSource>
The target sequence.
comparer
IEqualityComparer<TSource>
The custom equality comparer to use for the comparison.
IEnumerable<IEnumerable<TSource>>
A sequence containing all the elements that exist in the source
sequence, and not the target
sequence, without filtering duplicates.
ArgumentNullException
source
is null
-or-
comparer
is null
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