CKTIS / C#
System.Collections.Generic.HashSet: referencia práctica
System.Collections.Generic.HashSet: referencia práctica: HashSet<T> almacena valores únicos según la igualdad y el código hash proporcionados por su comparador.
Versión: .NET API; verified on .NET 10.0.14
Sintaxis
System.Collections.Generic.HashSet /* select a documented member or constructor */HashSet almacena valores únicos según la igualdad y el código hash proporcionados por su comparador.
Úsalo para pruebas de pertenencia, deduplicación y operaciones de conjuntos como unión o intersección.
La enumeración no está ordenada y los campos que afectan a GetHashCode no deben cambiar mientras el objeto esté en el conjunto.
Agregar un duplicado devuelve false; null se admite para tipos referencia si el comparador lo soporta.
El programa completo usa realmente System.Collections.Generic.HashSet; su stdout esperado exacto es 2.
Ejemplos
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var set = new HashSet<int> { 1, 1, 2 };
Console.WriteLine(set.Count);
Resultado
2
El programa completo usa realmente `System.Collections.Generic.HashSet`; su stdout esperado exacto es `2`.