Ler em inglês

Compartilhar via


Enumerable.ToHashSet Método

Definição

Sobrecargas

ToHashSet<TSource>(IEnumerable<TSource>)

Origem:
ToCollection.cs
Origem:
ToCollection.cs
Origem:
ToCollection.cs

Cria um HashSet<T> de um IEnumerable<T>.

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

Parâmetros de tipo

TSource

O tipo dos elementos de source.

Parâmetros

source
IEnumerable<TSource>

Um IEnumerable<T> por meio do qual um HashSet<T> será criado.

Retornos

HashSet<TSource>

Um HashSet<T> que contém valores do tipo TSource selecionados da sequência de entrada.

Exceções

source é null.

Confira também

Aplica-se a

.NET 9 e outras versões
Produto Versões
.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>)

Origem:
ToCollection.cs
Origem:
ToCollection.cs
Origem:
ToCollection.cs

Cria um HashSet<T> de um IEnumerable<T> usando o comparer para comparar chaves.

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

Parâmetros de tipo

TSource

O tipo dos elementos de source.

Parâmetros

source
IEnumerable<TSource>

Um IEnumerable<T> por meio do qual um HashSet<T> será criado.

comparer
IEqualityComparer<TSource>

Um IEqualityComparer<T> para comparar chaves.

Retornos

HashSet<TSource>

Um HashSet<T> que contém valores do tipo TSource selecionados da sequência de entrada.

Exceções

source é null.

Confira também

Aplica-se a

.NET 9 e outras versões
Produto Versões
.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