CKTIS / C#
System.Collections.Generic.Dictionary: practical reference
System.Collections.Generic.Dictionary: practical reference: Dictionary<TKey,TValue> maps unique keys to values according to an IEqualityComparer<TKey>.
Version: .NET API; verified on .NET 10.0.14
Syntax
System.Collections.Generic.Dictionary /* select a documented member or constructor */Dictionary<TKey,TValue> maps unique keys to values according to an IEqualityComparer.
Use it as a fast single-value index, with TryGetValue for an optional key that should not raise an exception.
The indexer throws KeyNotFoundException for a missing key. Adding entries during foreach invalidates the enumerator; on .NET Core 3.0 and later, Remove and Clear are documented exceptions and do not invalidate active enumerators.
A null key is forbidden, and concurrent writes require synchronization or ConcurrentDictionary<TKey,TValue>.
The complete program actually uses System.Collections.Generic.Dictionary; its exact expected stdout is 42.
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 = new Dictionary<string, int> { ["age"] = 42 };
Console.WriteLine(map["age"]);
Result
42
The complete program actually uses `System.Collections.Generic.Dictionary`; its exact expected stdout is `42`.