CKTIS / C#
System.Collections.Immutable.ImmutableHashSet: odniesienie praktyczne
System.Collections.Immutable.ImmutableHashSet: odniesienie praktyczne: ImmutableHashSet<T> zwraca nową wersję zbioru po Add/Remove.
Wersja: .NET API; verified on .NET 10.0.14
Składnia
System.Collections.Immutable.ImmutableHashSet /* select a documented member or constructor */ImmutableHashSet zwraca nową wersję zbioru po Add/Remove.
Stosuj do niezmiennych zestawów współdzielonych między czytelnikami.
Operacja bez zmiany może zwrócić tę samą instancję; elementy referencyjne nie są zamrażane.
Unikalność i null zależą od komparatora; mutable hash state nadal jest błędem.
Kompletny program rzeczywiście używa System.Collections.Immutable.ImmutableHashSet; oczekiwany stdout to dokładnie 1.
Przykłady
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 = ImmutableHashSet<int>.Empty.Add(1).Add(1);
Console.WriteLine(set.Count);
Wynik
1
Kompletny program rzeczywiście używa `System.Collections.Immutable.ImmutableHashSet`; oczekiwany stdout to dokładnie `1`.