Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / C#

System.Collections.Frozen.FrozenDictionary: referência prática

System.Collections.Frozen.FrozenDictionary: referência prática: FrozenDictionary<TKey,TValue> é um índice imutável preparado uma vez para pesquisas frequentes e rápidas por chave.

Versão: .NET 8+; verified on .NET 10.0.14

Sintaxe

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

FrozenDictionary<TKey,TValue> é um índice imutável preparado uma vez para pesquisas frequentes e rápidas por chave.

Constrói-o para dados duradouros de configuração ou consulta, lidos muito mais vezes do que são alterados.

A construção tem custo e fixa o comparador, pelo que não é adequado a dados reconstruídos frequentemente.

Chaves duplicadas falham durante a construção e alterações posteriores da origem não mudam o dicionário congelado.

O programa completo usa realmente System.Collections.Frozen.FrozenDictionary; o stdout exato esperado é 1.

Exemplos

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"]);

Resultado

1

O programa completo usa realmente `System.Collections.Frozen.FrozenDictionary`; o stdout exato esperado é `1`.

Fontes