Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.Collections.Generic.SortedDictionary: referencia práctica

System.Collections.Generic.SortedDictionary: referencia práctica: SortedDictionary<TKey,TValue> mantiene las claves ordenadas por IComparer<TKey> con búsquedas y actualizaciones logarítmicas.

Versión: .NET API; verified on .NET 10.0.14

Sintaxis

System.Collections.Generic.SortedDictionary /* select a documented member or constructor */

SortedDictionary<TKey,TValue> mantiene las claves ordenadas por IComparer con búsquedas y actualizaciones logarítmicas.

Úsalo cuando un mapa deba enumerar siempre las entradas en orden de clave.

Un resultado cero de Compare significa la misma clave aunque Equals discrepe; el comparador debe ser estable.

No se admite una clave null y cambiar el estado que participa en el orden rompe las premisas del árbol.

El programa completo usa realmente System.Collections.Generic.SortedDictionary; su stdout esperado exacto es 1,2.

Ejemplos

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 SortedDictionary<int, string> { [2] = "b", [1] = "a" };
Console.WriteLine(string.Join(",", map.Keys));

Resultado

1,2

El programa completo usa realmente `System.Collections.Generic.SortedDictionary`; su stdout esperado exacto es `1,2`.

Fuentes