CKTIS / C#
System.Collections.Generic.Dictionary: praktická reference
System.Collections.Generic.Dictionary: praktická reference: Dictionary<TKey,TValue> mapuje jedinečné klíče na hodnoty podle IEqualityComparer<TKey>.
Verze: .NET API; verified on .NET 10.0.14
Syntaxe
System.Collections.Generic.Dictionary /* select a documented member or constructor */Dictionary<TKey,TValue> mapuje jedinečné klíče na hodnoty podle IEqualityComparer.
Použijte jej jako rychlý jednohodnotový index; TryGetValue zpracuje volitelný klíč bez výjimky.
Indexer pro chybějící klíč vyvolá KeyNotFoundException. Přidání položek během foreach zneplatní enumerátor; v .NET Core 3.0 a novějším jsou Remove a Clear zdokumentované výjimky a aktivní enumerátory nezneplatní.
Klíč null je zakázán a souběžné zápisy vyžadují synchronizaci nebo ConcurrentDictionary<TKey,TValue>.
Úplný program skutečně používá System.Collections.Generic.Dictionary; přesně očekávaný stdout je 42.
Pří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 = new Dictionary<string, int> { ["age"] = 42 };
Console.WriteLine(map["age"]);
Výsledek
42
Úplný program skutečně používá `System.Collections.Generic.Dictionary`; přesně očekávaný stdout je `42`.