Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Collections.Immutable.ImmutableDictionary: praktická referencia

System.Collections.Immutable.ImmutableDictionary: praktická referencia: ImmutableDictionary<TKey,TValue> po každej skutočnej zmene vráti novú štrukturálne zdieľanú mapu.

Verzia: .NET API; verified on .NET 10.0.14

Syntax

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

ImmutableDictionary<TKey,TValue> po každej skutočnej zmene vráti novú štrukturálne zdieľanú mapu.

Použite ho pre bezpečné snímky a atomicky publikované aktualizácie nahradením referencie mapy.

Add odmietne existujúci kľúč, SetItem nahradí hodnotu a comparer zostáva súčasťou politiky slovníka.

Chýbajúci kľúč cez indexer vyvolá výnimku a kľúč null nie je povolený.

Úplný program skutočne používa System.Collections.Immutable.ImmutableDictionary; presne očakávaný stdout je 4.

Príklady

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

Výsledok

4

Úplný program skutočne používa `System.Collections.Immutable.ImmutableDictionary`; presne očakávaný stdout je `4`.

Zdroje