WissensdatenbankPrüfungszentrum
DEDeutsch
Sprache wählen13

CKTIS / C#

System.Collections.Generic.SortedDictionary: praktische Referenz

System.Collections.Generic.SortedDictionary: praktische Referenz: SortedDictionary<TKey,TValue> hält Schlüssel gemäß IComparer<TKey> geordnet und bietet logarithmische Such- und Änderungsoperationen.

Version: .NET API; verified on .NET 10.0.14

Syntax

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

SortedDictionary<TKey,TValue> hält Schlüssel gemäß IComparer geordnet und bietet logarithmische Such- und Änderungsoperationen.

Geeignet, wenn eine Map Einträge stets in Schlüsselreihenfolge enumerieren muss.

Compare mit Ergebnis null bedeutet denselben Schlüssel, auch wenn Equals widerspricht; der Comparer muss stabil bleiben.

Ein null-Schlüssel ist verboten, und Änderungen an ordnungsrelevantem Schlüsselzustand verletzen die Baumstruktur.

Das vollständige Programm verwendet System.Collections.Generic.SortedDictionary tatsächlich; die exakt erwartete stdout-Ausgabe ist 1,2.

Beispiele

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

Ergebnis

1,2

Das vollständige Programm verwendet `System.Collections.Generic.SortedDictionary` tatsächlich; die exakt erwartete stdout-Ausgabe ist `1,2`.

Quellen