Base de connaissancesCentre d’examen
FRFrançais
Choisir la langue13

CKTIS / C#

System.Collections.Generic.SortedDictionary: référence pratique

System.Collections.Generic.SortedDictionary: référence pratique: SortedDictionary<TKey,TValue> maintient les clés ordonnées par IComparer<TKey> avec recherches et mises à jour logarithmiques.

Version : .NET API; verified on .NET 10.0.14

Syntaxe

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

SortedDictionary<TKey,TValue> maintient les clés ordonnées par IComparer avec recherches et mises à jour logarithmiques.

Utilisez-le lorsqu’une map doit toujours énumérer ses entrées dans l’ordre des clés.

Un résultat Compare égal à zéro signifie la même clé même si Equals diverge ; le comparateur doit rester stable.

Une clé null est interdite et modifier l’état participant à l’ordre des clés corrompt les hypothèses de l’arbre.

Le programme complet utilise réellement System.Collections.Generic.SortedDictionary ; sa sortie stdout exacte attendue est 1,2.

Exemples

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

Résultat

1,2

Le programme complet utilise réellement `System.Collections.Generic.SortedDictionary` ; sa sortie stdout exacte attendue est `1,2`.

Sources