CKTIS / C#
System.Collections.Immutable.ImmutableDictionary: praktična referenca
System.Collections.Immutable.ImmutableDictionary: praktična referenca: ImmutableDictionary<TKey,TValue> po vsaki dejanski spremembi vrne nov strukturno deljen slovar.
Različica: .NET API; verified on .NET 10.0.14
Sintaksa
System.Collections.Immutable.ImmutableDictionary /* select a documented member or constructor */ImmutableDictionary<TKey,TValue> po vsaki dejanski spremembi vrne nov strukturno deljen slovar.
Uporabite ga za varne posnetke in atomsko objavljene posodobitve z zamenjavo reference slovarja.
Add zavrne obstoječi ključ, SetItem zamenja vrednost, comparer pa ostane del politike slovarja.
Manjkajoči ključ prek indeksatorja sproži izjemo in ključ null ni dovoljen.
Celoten program dejansko uporabi System.Collections.Immutable.ImmutableDictionary; natančno pričakovani stdout je 4.
Primeri
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"]);
Rezultat
4
Celoten program dejansko uporabi `System.Collections.Immutable.ImmutableDictionary`; natančno pričakovani stdout je `4`.