Enumerable.IntersectBy Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>) |
Produces the set intersection of two sequences according to a specified key selector function. |
IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>) |
Produces the set intersection of two sequences according to a specified key selector function. |
IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>)
- Source:
- Intersect.cs
- Source:
- Intersect.cs
- Source:
- Intersect.cs
Produces the set intersection of two sequences according to a specified key selector function.
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<TSource> ^ IntersectBy(System::Collections::Generic::IEnumerable<TSource> ^ first, System::Collections::Generic::IEnumerable<TKey> ^ second, Func<TSource, TKey> ^ keySelector, System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public static System.Collections.Generic.IEnumerable<TSource> IntersectBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TKey> second, Func<TSource,TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer);
static member IntersectBy : seq<'Source> * seq<'Key> * Func<'Source, 'Key> * System.Collections.Generic.IEqualityComparer<'Key> -> seq<'Source>
<Extension()>
Public Function IntersectBy(Of TSource, TKey) (first As IEnumerable(Of TSource), second As IEnumerable(Of TKey), keySelector As Func(Of TSource, TKey), comparer As IEqualityComparer(Of TKey)) As IEnumerable(Of TSource)
Type Parameters
- TSource
The type of the elements of the input sequences.
- TKey
The type of key to identify elements by.
Parameters
- first
- IEnumerable<TSource>
An IEnumerable<T> whose distinct elements that also appear in second
will be returned.
- second
- IEnumerable<TKey>
An IEnumerable<T> whose distinct elements that also appear in the first sequence will be returned.
- keySelector
- Func<TSource,TKey>
A function to extract the key for each element.
- comparer
- IEqualityComparer<TKey>
An IEqualityComparer<T> to compare keys.
Returns
A sequence that contains the elements that form the set intersection of two sequences.
Exceptions
first
or second
is null
.
Remarks
This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator
method directly or by using foreach
in C# or For Each
in Visual Basic.
The intersection of two sets A and B is defined as the set that contains all the elements of A that also appear in B, but no other elements.
When the object returned by this method is enumerated, Intersect
yields distinct elements occurring in both sequences in the order in which they appear in first
.
If comparer
is null
, the default equality comparer, Default, is used to compare values.
See also
Applies to
IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>)
- Source:
- Intersect.cs
- Source:
- Intersect.cs
- Source:
- Intersect.cs
Produces the set intersection of two sequences according to a specified key selector function.
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<TSource> ^ IntersectBy(System::Collections::Generic::IEnumerable<TSource> ^ first, System::Collections::Generic::IEnumerable<TKey> ^ second, Func<TSource, TKey> ^ keySelector);
public static System.Collections.Generic.IEnumerable<TSource> IntersectBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TKey> second, Func<TSource,TKey> keySelector);
static member IntersectBy : seq<'Source> * seq<'Key> * Func<'Source, 'Key> -> seq<'Source>
<Extension()>
Public Function IntersectBy(Of TSource, TKey) (first As IEnumerable(Of TSource), second As IEnumerable(Of TKey), keySelector As Func(Of TSource, TKey)) As IEnumerable(Of TSource)
Type Parameters
- TSource
The type of the elements of the input sequences.
- TKey
The type of key to identify elements by.
Parameters
- first
- IEnumerable<TSource>
An IEnumerable<T> whose distinct elements that also appear in second
will be returned.
- second
- IEnumerable<TKey>
An IEnumerable<T> whose distinct elements that also appear in the first sequence will be returned.
- keySelector
- Func<TSource,TKey>
A function to extract the key for each element.
Returns
A sequence that contains the elements that form the set intersection of two sequences.
Exceptions
first
or second
is null
.
Remarks
This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator
method directly or by using foreach
in C# or For Each
in Visual Basic.
The intersection of two sets A and B is defined as the set that contains all the elements of A that also appear in B, but no other elements.
When the object returned by this method is enumerated, Intersect
yields distinct elements occurring in both sequences in the order in which they appear in first
.
The default equality comparer, Default, is used to compare values.