Enumerable.ToHashSet 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
ToHashSet<TSource>(IEnumerable<TSource>) |
從 IEnumerable<T> 建立 HashSet<T>。 |
ToHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>) |
使用比較金鑰的 |
從 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);
C#
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>
HashSet<T>,包含從輸入序列選取之 TSource
類型的值。
例外狀況
source
為 null
。
另請參閱
適用於
.NET 9 和其他版本
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.1 |
使用比較金鑰的 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);
C#
public static System.Collections.Generic.HashSet<TSource> ToHashSet<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? comparer);
C#
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>
HashSet<T>,包含從輸入序列選取之 TSource
類型的值。
例外狀況
source
為 null
。
另請參閱
適用於
.NET 9 和其他版本
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.1 |