CKTIS / C#
System.Collections.Generic.HashSet: практическа справка
System.Collections.Generic.HashSet: практическа справка: HashSet<T> съхранява уникални стойности според равенството и хеша, предоставени от comparer.
Версия: .NET API; verified on .NET 10.0.14
Синтаксис
System.Collections.Generic.HashSet /* select a documented member or constructor */HashSet съхранява уникални стойности според равенството и хеша, предоставени от comparer.
Използвайте го за проверки за членство, премахване на дубликати и операции като обединение или сечение.
Обхождането не е сортирано и полетата, които влияят на GetHashCode, не бива да се променят, докато обектът е в множеството.
Добавянето на дубликат връща false; null е разрешен за референтни типове, ако comparer го поддържа.
Пълната програма действително използва System.Collections.Generic.HashSet; точният очакван stdout е 2.
Примери
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);
Резултат
2
Пълната програма действително използва `System.Collections.Generic.HashSet`; точният очакван stdout е `2`.