CKTIS / C#
System.Collections.Generic.HashSet: praktická referencia
System.Collections.Generic.HashSet: praktická referencia: HashSet<T> ukladá jedinečné hodnoty podľa rovnosti a hashu poskytovaných comparerom.
Verzia: .NET API; verified on .NET 10.0.14
Syntax
System.Collections.Generic.HashSet /* select a documented member or constructor */HashSet ukladá jedinečné hodnoty podľa rovnosti a hashu poskytovaných comparerom.
Použite ho na testy členstva, deduplikáciu a množinové operácie, napríklad zjednotenie alebo prienik.
Enumerácia nie je zoradená a polia ovplyvňujúce GetHashCode sa nesmú meniť, kým je objekt v množine.
Pridanie duplicity vráti false; null je pre referenčné typy povolený, ak ho comparer podporuje.
Úplný program skutočne používa System.Collections.Generic.HashSet; presne očakávaný stdout je 2.
Príklady
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);
Výsledok
2
Úplný program skutočne používa `System.Collections.Generic.HashSet`; presne očakávaný stdout je `2`.