Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Collections.Immutable.ImmutableDictionary: odniesienie praktyczne

System.Collections.Immutable.ImmutableDictionary: odniesienie praktyczne: ImmutableDictionary<TKey,TValue> zwraca nową, strukturalnie współdzieloną mapę po zmianie.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

System.Collections.Immutable.ImmutableDictionary /* select a documented member or constructor */

ImmutableDictionary<TKey,TValue> zwraca nową, strukturalnie współdzieloną mapę po zmianie.

Stosuj do bezpiecznych migawek i aktualizacji publikowanych atomowo jako nowa referencja.

Add odrzuca istniejący klucz; SetItem zastępuje, a komparator jest utrwalony.

Brak klucza w indekserze zgłasza wyjątek; null key jest niedozwolony.

Kompletny program rzeczywiście używa System.Collections.Immutable.ImmutableDictionary; oczekiwany stdout to dokładnie 4.

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 map = ImmutableDictionary<string, int>.Empty.Add("x", 4);
Console.WriteLine(map["x"]);

Wynik

4

Kompletny program rzeczywiście używa `System.Collections.Immutable.ImmutableDictionary`; oczekiwany stdout to dokładnie `4`.

Źródła