CKTIS / C#
System.Collections.Generic.HashSet: praktična referenca
System.Collections.Generic.HashSet: praktična referenca: HashSet<T> hrani enolične vrednosti glede na enakost in zgoščeno vrednost, ki ju določa comparer.
Različica: .NET API; verified on .NET 10.0.14
Sintaksa
System.Collections.Generic.HashSet /* select a documented member or constructor */HashSet hrani enolične vrednosti glede na enakost in zgoščeno vrednost, ki ju določa comparer.
Uporabite ga za preverjanje članstva, odstranjevanje dvojnikov in množične operacije, kot sta unija ali presek.
Enumeracija ni razvrščena in polja, ki vplivajo na GetHashCode, se med članstvom objekta ne smejo spremeniti.
Dodajanje dvojnika vrne false; null je dovoljen za referenčne tipe, če ga comparer podpira.
Celoten program dejansko uporabi System.Collections.Generic.HashSet; natančno pričakovani stdout je 2.
Primeri
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);
Rezultat
2
Celoten program dejansko uporabi `System.Collections.Generic.HashSet`; natančno pričakovani stdout je `2`.