База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / C#

System.Collections.Immutable.ImmutableDictionary: практическа справка

System.Collections.Immutable.ImmutableDictionary: практическа справка: ImmutableDictionary<TKey,TValue> връща нова структурно споделена карта след всяка действителна промяна.

Версия: .NET API; verified on .NET 10.0.14

Синтаксис

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

ImmutableDictionary<TKey,TValue> връща нова структурно споделена карта след всяка действителна промяна.

Използвайте го за безопасни снимки и атомарно публикувани промени чрез замяна на референцията към картата.

Add отхвърля съществуващ ключ, SetItem заменя стойността, а comparer остава част от политиката.

Липсващ ключ през индексатора хвърля изключение и ключ null не е разрешен.

Пълната програма действително използва System.Collections.Immutable.ImmutableDictionary; точният очакван stdout е 4.

Примери

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

Резултат

4

Пълната програма действително използва `System.Collections.Immutable.ImmutableDictionary`; точният очакван stdout е `4`.

Източници