CKTIS / C#
System.Collections.Generic.Dictionary: praktična referenca
System.Collections.Generic.Dictionary: praktična referenca: Dictionary<TKey,TValue> preslikava jedinstvene ključe na vrijednosti prema IEqualityComparer<TKey>.
Verzija: .NET API; verified on .NET 10.0.14
Sintaksa
System.Collections.Generic.Dictionary /* select a documented member or constructor */Dictionary<TKey,TValue> preslikava jedinstvene ključe na vrijednosti prema IEqualityComparer.
Koristite ga kao brzi indeks jedne vrijednosti; TryGetValue obrađuje neobvezni ključ bez iznimke.
Indeksator za nedostajući ključ baca KeyNotFoundException. Dodavanje stavki tijekom foreach poništava enumerator; u .NET Core 3.0 i novijem Remove i Clear dokumentirane su iznimke i ne poništavaju aktivne enumeratore.
Null ključ je zabranjen, a istodobna pisanja zahtijevaju sinkronizaciju ili ConcurrentDictionary<TKey,TValue>.
Cijeli program doista koristi System.Collections.Generic.Dictionary; točno očekivani stdout jest 42.
Primjeri
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"]);
Rezultat
42
Cijeli program doista koristi `System.Collections.Generic.Dictionary`; točno očekivani stdout jest `42`.