CKTIS / C#
System.Collections.Frozen.FrozenDictionary: praktická reference
System.Collections.Frozen.FrozenDictionary: praktická reference: FrozenDictionary<TKey,TValue> je neměnný index jednou připravený pro rychlá a častá vyhledávání podle klíče.
Verze: .NET 8+; verified on .NET 10.0.14
Syntaxe
System.Collections.Frozen.FrozenDictionary /* select a documented member or constructor */FrozenDictionary<TKey,TValue> je neměnný index jednou připravený pro rychlá a častá vyhledávání podle klíče.
Vytvořte jej pro dlouhodobá konfigurační nebo vyhledávací data, která se mnohem častěji čtou než mění.
Vytvoření má cenu a zafixuje comparer, proto se nehodí pro data často sestavovaná znovu.
Duplicitní klíče při sestavení selžou a pozdější změny zdrojové kolekce frozen dictionary nezmění.
Úplný program skutečně používá System.Collections.Frozen.FrozenDictionary; přesně očekávaný stdout je 1.
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> { ["a"] = 1 }.ToFrozenDictionary();
Console.WriteLine(map["a"]);
Výsledek
1
Úplný program skutečně používá `System.Collections.Frozen.FrozenDictionary`; přesně očekávaný stdout je `1`.