CKTIS / C#
System.Collections.Immutable.ImmutableDictionary: practical reference
System.Collections.Immutable.ImmutableDictionary: practical reference: ImmutableDictionary<TKey,TValue> returns a new structurally shared map after each effective change.
Version: .NET API; verified on .NET 10.0.14
Syntax
System.Collections.Immutable.ImmutableDictionary /* select a documented member or constructor */ImmutableDictionary<TKey,TValue> returns a new structurally shared map after each effective change.
Use it for safe snapshots and updates published atomically by replacing one map reference with another.
Add rejects an existing key, SetItem replaces its value, and the comparer remains part of the dictionary policy.
A missing key through the indexer throws, and a null key is not permitted.
The complete program actually uses System.Collections.Immutable.ImmutableDictionary; its exact expected stdout is 4.
Examples
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"]);
Result
4
The complete program actually uses `System.Collections.Immutable.ImmutableDictionary`; its exact expected stdout is `4`.