Enumerable.IntersectBy 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>)
根据指定的键选择器函数生成两个序列的集交集。
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)
类型参数
- TSource
输入序列中的元素的类型。
- TKey
要标识元素的键的类型。
参数
- first
- IEnumerable<TSource>
一个 IEnumerable<T>,将返回其也出现在 second
中的非重复元素。
- second
- IEnumerable<TKey>
一个 IEnumerable<T> 序列,其中的同时出现在第一个序列中的非重复元素将被返回。
- keySelector
- Func<TSource,TKey>
用于提取每个元素的键的函数。
- comparer
- IEqualityComparer<TKey>
用于比较键的 IEqualityComparer<T>。
返回
- IEnumerable<TSource>
包含组成两个序列交集的元素的序列。
例外
first
或 second
为 null
。
注解
此方法通过使用延迟执行来实现。 即时返回值是一个对象,用于存储执行操作所需的所有信息。 除非对象通过直接调用其方法或在 foreach
Visual C# 或 For Each
Visual Basic 中使用来枚举对象GetEnumerator
,否则不会执行此方法表示的查询。
两组 A 和 B 的交集定义为包含 A 的所有元素的集,这些元素也出现在 B 中,但不包含其他元素。
枚举此方法返回的对象时, Intersect
按照两个序列 first
中出现的不同元素的顺序生成不同的元素。
如果comparer
为 null
Default,则使用默认相等比较器比较值。
另请参阅
适用于
IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>)
根据指定的键选择器函数生成两个序列的集交集。
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)
类型参数
- TSource
输入序列中的元素的类型。
- TKey
要标识元素的键的类型。
参数
- first
- IEnumerable<TSource>
一个 IEnumerable<T>,将返回其也出现在 second
中的非重复元素。
- second
- IEnumerable<TKey>
一个 IEnumerable<T> 序列,其中的同时出现在第一个序列中的非重复元素将被返回。
- keySelector
- Func<TSource,TKey>
用于提取每个元素的键的函数。
返回
- IEnumerable<TSource>
包含组成两个序列交集的元素的序列。
例外
first
或 second
为 null
。
注解
此方法通过使用延迟执行来实现。 即时返回值是一个对象,用于存储执行操作所需的所有信息。 除非对象通过直接调用其方法或在 foreach
Visual C# 或 For Each
Visual Basic 中使用来枚举对象GetEnumerator
,否则不会执行此方法表示的查询。
两组 A 和 B 的交集定义为包含 A 的所有元素的集,这些元素也出现在 B 中,但不包含其他元素。
枚举此方法返回的对象时, Intersect
按照两个序列 first
中出现的不同元素的顺序生成不同的元素。
默认相等比较器 Default用于比较值。