Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / C#

System.Collections.Generic.HashSet: praktična referenca

System.Collections.Generic.HashSet: praktična referenca: HashSet<T> sprema jedinstvene vrijednosti prema jednakosti i hashu koje daje comparer.

Verzija: .NET API; verified on .NET 10.0.14

Sintaksa

System.Collections.Generic.HashSet /* select a documented member or constructor */

HashSet sprema jedinstvene vrijednosti prema jednakosti i hashu koje daje comparer.

Koristite ga za provjere članstva, uklanjanje duplikata i skupovne operacije poput unije ili presjeka.

Enumeracija nije sortirana, a polja koja utječu na GetHashCode ne smiju se mijenjati dok je objekt u skupu.

Dodavanje duplikata vraća false; null je dopušten za referentne tipove ako ga comparer podržava.

Cijeli program doista koristi System.Collections.Generic.HashSet; točno očekivani stdout jest 2.

Primjeri

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

Cijeli program doista koristi `System.Collections.Generic.HashSet`; točno očekivani stdout jest `2`.

Izvori