英語で読む

次の方法で共有


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>)

ソース:
ToCollection.cs
ソース:
ToCollection.cs
ソース:
ToCollection.cs

IEnumerable<T> から HashSet<T> を作成します。

C#
public static System.Collections.Generic.HashSet<TSource> ToHashSet<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);

型パラメーター

TSource

source の要素の型。

パラメーター

source
IEnumerable<TSource>

HashSet<T> の作成元の IEnumerable<T>

戻り値

HashSet<TSource>

入力シーケンスから選択された TSource 型の値を格納する HashSet<T>

例外

sourcenull です。

こちらもご覧ください

適用対象

.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

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

ソース:
ToCollection.cs
ソース:
ToCollection.cs
ソース:
ToCollection.cs

comparer を使用して IEnumerable<T>から HashSet<T> を作成し、キーを比較します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IEnumerable<TSource>

HashSet<T> の作成元の IEnumerable<T>

comparer
IEqualityComparer<TSource>

キーを比較する IEqualityComparer<T>

戻り値

HashSet<TSource>

入力シーケンスから選択された TSource 型の値を格納する HashSet<T>

例外

sourcenull です。

こちらもご覧ください

適用対象

.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