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

CKTIS / C#

System.Collections.Generic.SortedDictionary: referência prática

System.Collections.Generic.SortedDictionary: referência prática: SortedDictionary<TKey,TValue> mantém as chaves ordenadas por IComparer<TKey> com pesquisas e atualizações logarítmicas.

Versão: .NET API; verified on .NET 10.0.14

Sintaxe

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

SortedDictionary<TKey,TValue> mantém as chaves ordenadas por IComparer com pesquisas e atualizações logarítmicas.

Usa-o quando um mapa tem de enumerar sempre as entradas pela ordem das chaves.

Compare igual a zero significa a mesma chave mesmo que Equals discorde; o comparador tem de permanecer estável.

Uma chave null é proibida e alterar o estado usado na ordenação viola as premissas da árvore.

O programa completo usa realmente System.Collections.Generic.SortedDictionary; o stdout exato esperado é 1,2.

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

Resultado

1,2

O programa completo usa realmente `System.Collections.Generic.SortedDictionary`; o stdout exato esperado é `1,2`.

Fontes