Прочитать на английском

Поделиться через


Enumerable.ToHashSet Метод

Определение

Перегрузки

ToHashSet<TSource>(IEnumerable<TSource>)

Создает HashSet<T> из IEnumerable<T>.

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

Создает HashSet<T> из IEnumerable<T> с использованием comparer для сравнения ключей.

ToHashSet<TSource>(IEnumerable<TSource>)

Исходный код:
ToCollection.cs
Исходный код:
ToCollection.cs
Исходный код:
ToCollection.cs

Создает HashSet<T> из IEnumerable<T>.

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

Параметры типа

TSource

Тип элементов source.

Параметры

source
IEnumerable<TSource>

IEnumerable<T>, на основе которого создается HashSet<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

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

Исходный код:
ToCollection.cs
Исходный код:
ToCollection.cs
Исходный код:
ToCollection.cs

Создает HashSet<T> из IEnumerable<T> с использованием 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);

Параметры типа

TSource

Тип элементов source.

Параметры

source
IEnumerable<TSource>

IEnumerable<T>, на основе которого создается HashSet<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