Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / C#

System.Collections.Generic.SortedDictionary: riferimento pratico

System.Collections.Generic.SortedDictionary: riferimento pratico: SortedDictionary<TKey,TValue> mantiene le chiavi ordinate da IComparer<TKey> con ricerche e aggiornamenti logaritmici.

Versione: .NET API; verified on .NET 10.0.14

Sintassi

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

SortedDictionary<TKey,TValue> mantiene le chiavi ordinate da IComparer con ricerche e aggiornamenti logaritmici.

Usalo quando una mappa deve enumerare sempre le voci in ordine di chiave.

Compare uguale a zero indica la stessa chiave anche se Equals non concorda; il comparer deve restare stabile.

Una chiave null è vietata e modificare lo stato usato per l’ordinamento compromette le ipotesi dell’albero.

Il programma completo usa realmente System.Collections.Generic.SortedDictionary; lo stdout esatto atteso è 1,2.

Esempi

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

Risultato

1,2

Il programma completo usa realmente `System.Collections.Generic.SortedDictionary`; lo stdout esatto atteso è `1,2`.

Fonti