Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / C#

System.Collections.Immutable.ImmutableDictionary: riferimento pratico

System.Collections.Immutable.ImmutableDictionary: riferimento pratico: ImmutableDictionary<TKey,TValue> restituisce una nuova mappa strutturalmente condivisa dopo ogni modifica effettiva.

Versione: .NET API; verified on .NET 10.0.14

Sintassi

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

ImmutableDictionary<TKey,TValue> restituisce una nuova mappa strutturalmente condivisa dopo ogni modifica effettiva.

Usalo per snapshot sicuri e aggiornamenti pubblicati atomicamente sostituendo un riferimento alla mappa.

Add rifiuta una chiave esistente, SetItem ne sostituisce il valore e il comparer resta parte della politica.

Una chiave mancante tramite indicizzatore genera un’eccezione e una chiave null non è consentita.

Il programma completo usa realmente System.Collections.Immutable.ImmutableDictionary; lo stdout esatto atteso è 4.

Esempi

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"]);

Risultato

4

Il programma completo usa realmente `System.Collections.Immutable.ImmutableDictionary`; lo stdout esatto atteso è `4`.

Fonti