Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Collections.Frozen.FrozenDictionary: praktická referencia

System.Collections.Frozen.FrozenDictionary: praktická referencia: FrozenDictionary<TKey,TValue> je nemenný index raz pripravený na rýchle a časté vyhľadávanie podľa kľúča.

Verzia: .NET 8+; verified on .NET 10.0.14

Syntax

System.Collections.Frozen.FrozenDictionary /* select a documented member or constructor */

FrozenDictionary<TKey,TValue> je nemenný index raz pripravený na rýchle a časté vyhľadávanie podľa kľúča.

Vytvorte ho pre dlhodobé konfiguračné alebo vyhľadávacie údaje, ktoré sa oveľa častejšie čítajú než menia.

Vytvorenie má cenu a zafixuje comparer, preto sa nehodí pre údaje často zostavované znova.

Duplicitné kľúče pri zostavení zlyhajú a neskoršie zmeny zdrojovej kolekcie frozen dictionary nezmenia.

Úplný program skutočne používa System.Collections.Frozen.FrozenDictionary; presne očakávaný stdout je 1.

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> { ["a"] = 1 }.ToFrozenDictionary();
Console.WriteLine(map["a"]);

Výsledok

1

Úplný program skutočne používa `System.Collections.Frozen.FrozenDictionary`; presne očakávaný stdout je `1`.

Zdroje