Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / C#

System.Collections.Generic.SortedDictionary: praktična referenca

System.Collections.Generic.SortedDictionary: praktična referenca: SortedDictionary<TKey,TValue> ohranja ključe urejene z IComparer<TKey> ter omogoča logaritmično iskanje in posodobitve.

Različica: .NET API; verified on .NET 10.0.14

Sintaksa

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

SortedDictionary<TKey,TValue> ohranja ključe urejene z IComparer ter omogoča logaritmično iskanje in posodobitve.

Uporabite ga, ko mora slovar vedno enumerirati vnose po vrstnem redu ključev.

Rezultat Compare nič pomeni isti ključ tudi ob drugačnem Equals; comparer mora ostati stabilen.

Ključ null je prepovedan, sprememba stanja, ki določa vrstni red ključa, pa krši predpostavke drevesa.

Celoten program dejansko uporabi System.Collections.Generic.SortedDictionary; natančno pričakovani stdout je 1,2.

Primeri

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

Rezultat

1,2

Celoten program dejansko uporabi `System.Collections.Generic.SortedDictionary`; natančno pričakovani stdout je `1,2`.

Viri