CKTIS / C#
System.Collections.Generic.Dictionary: praktická referencia
System.Collections.Generic.Dictionary: praktická referencia: Dictionary<TKey,TValue> mapuje jedinečné kľúče na hodnoty podľa IEqualityComparer<TKey>.
Verzia: .NET API; verified on .NET 10.0.14
Syntax
System.Collections.Generic.Dictionary /* select a documented member or constructor */Dictionary<TKey,TValue> mapuje jedinečné kľúče na hodnoty podľa IEqualityComparer.
Použite ho ako rýchly jednohodnotový index; TryGetValue spracuje voliteľný kľúč bez výnimky.
Indexer pre chýbajúci kľúč vyvolá KeyNotFoundException. Pridanie položiek počas foreach zneplatní enumerátor; v .NET Core 3.0 a novšom sú Remove a Clear zdokumentované výnimky a aktívne enumerátory nezneplatnia.
Kľúč null je zakázaný a súbežné zápisy vyžadujú synchronizáciu alebo ConcurrentDictionary<TKey,TValue>.
Úplný program skutočne používa System.Collections.Generic.Dictionary; presne očakávaný stdout je 42.
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 = new Dictionary<string, int> { ["age"] = 42 };
Console.WriteLine(map["age"]);
Výsledok
42
Úplný program skutočne používa `System.Collections.Generic.Dictionary`; presne očakávaný stdout je `42`.