Enumerable.ToHashSet 方法

定义

重载

ToHashSet<TSource>(IEnumerable<TSource>)

IEnumerable<T> 创建一个 HashSet<T>

ToHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

使用 comparer 通过 IEnumerable<T> 创建 HashSet<T>,以用于比较键。

ToHashSet<TSource>(IEnumerable<TSource>)

Source:
ToCollection.cs
Source:
ToCollection.cs
Source:
ToCollection.cs

IEnumerable<T> 创建一个 HashSet<T>

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::HashSet<TSource> ^ ToHashSet(System::Collections::Generic::IEnumerable<TSource> ^ source);
public static System.Collections.Generic.HashSet<TSource> ToHashSet<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);
static member ToHashSet : seq<'Source> -> System.Collections.Generic.HashSet<'Source>
<Extension()>
Public Function ToHashSet(Of TSource) (source As IEnumerable(Of TSource)) As HashSet(Of TSource)

类型参数

TSource

source 的元素类型。

参数

source
IEnumerable<TSource>

要从其创建 HashSet<T>IEnumerable<T>

返回

HashSet<TSource>

一个包含从输入序列中选择的类型为 TSource 的值的 HashSet<T>

例外

sourcenull

另请参阅

适用于

ToHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

Source:
ToCollection.cs
Source:
ToCollection.cs
Source:
ToCollection.cs

使用 comparer 通过 IEnumerable<T> 创建 HashSet<T>,以用于比较键。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::HashSet<TSource> ^ ToHashSet(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static System.Collections.Generic.HashSet<TSource> ToHashSet<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? comparer);
public static System.Collections.Generic.HashSet<TSource> ToHashSet<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource> comparer);
static member ToHashSet : seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Collections.Generic.HashSet<'Source>
<Extension()>
Public Function ToHashSet(Of TSource) (source As IEnumerable(Of TSource), comparer As IEqualityComparer(Of TSource)) As HashSet(Of TSource)

类型参数

TSource

source 的元素类型。

参数

source
IEnumerable<TSource>

要从其创建 HashSet<T>IEnumerable<T>

comparer
IEqualityComparer<TSource>

用于比较键的 IEqualityComparer<T>

返回

HashSet<TSource>

一个包含从输入序列中选择的类型为 TSource 的值的 HashSet<T>

例外

sourcenull

另请参阅

适用于