Enumerable.IntersectBy 方法

定义

重载

IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>)

根据指定的键选择器函数生成两个序列的集合交集。

IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>)

根据指定的键选择器函数生成两个序列的集合交集。

IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Source:
Intersect.cs
Source:
Intersect.cs
Source:
Intersect.cs

根据指定的键选择器函数生成两个序列的集合交集。

C#
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);

类型参数

TSource

输入序列中的元素的类型。

TKey

要标识元素的键的类型。

参数

first
IEnumerable<TSource>

一个 IEnumerable<T>,将返回其也出现在 second 中的非重复元素。

second
IEnumerable<TKey>

一个 IEnumerable<T> 序列,其中的同时出现在第一个序列中的非重复元素将被返回。

keySelector
Func<TSource,TKey>

用于提取每个元素的键的函数。

comparer
IEqualityComparer<TKey>

用于比较键的 IEqualityComparer<T>

返回

IEnumerable<TSource>

包含组成两个序列交集的元素的序列。

例外

firstsecondnull

注解

此方法通过使用延迟执行来实现。 即时返回值是一个对象,用于存储执行操作所需的所有信息。 在通过直接调用GetEnumerator其方法或通过在 C# For Eachforeach Visual Basic 中使用 来枚举对象之前,不会执行此方法表示的查询。

两个集 A 和 B 的交集定义为包含 A 的所有元素的集,这些元素也出现在 B 中,但不包含其他元素。

当枚举此方法返回的对象时, Intersect 会生成两个序列中出现的不同元素,其出现在 中 first的顺序是不同的。

如果 comparernull,则使用默认相等比较器 Default来比较值。

另请参阅

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9

IntersectBy<TSource,TKey>(IEnumerable<TSource>, IEnumerable<TKey>, Func<TSource,TKey>)

Source:
Intersect.cs
Source:
Intersect.cs
Source:
Intersect.cs

根据指定的键选择器函数生成两个序列的集合交集。

C#
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);

类型参数

TSource

输入序列中的元素的类型。

TKey

要标识元素的键的类型。

参数

first
IEnumerable<TSource>

一个 IEnumerable<T>,将返回其也出现在 second 中的非重复元素。

second
IEnumerable<TKey>

一个 IEnumerable<T> 序列,其中的同时出现在第一个序列中的非重复元素将被返回。

keySelector
Func<TSource,TKey>

用于提取每个元素的键的函数。

返回

IEnumerable<TSource>

包含组成两个序列交集的元素的序列。

例外

firstsecondnull

注解

此方法通过使用延迟执行来实现。 即时返回值是一个对象,用于存储执行操作所需的所有信息。 在通过直接调用GetEnumerator其方法或通过在 C# For Eachforeach Visual Basic 中使用 来枚举对象之前,不会执行此方法表示的查询。

两个集 A 和 B 的交集定义为包含 A 的所有元素的集,这些元素也出现在 B 中,但不包含其他元素。

当枚举此方法返回的对象时, Intersect 会生成两个序列中出现的不同元素,其出现在 中 first的顺序是不同的。

默认相等比较器 Default用于比较值。

另请参阅

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9