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

CKTIS / C#

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

System.Collections.Generic.SortedSet: referência prática: SortedSet<T> mantém elementos únicos pela ordem definida pelo comparador.

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

Sintaxe

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

SortedSet mantém elementos únicos pela ordem definida pelo comparador.

Usa-o para conjuntos ordenados e consultas de intervalos que precisam de pertença ordenada.

A unicidade é determinada por Compare igual a zero e um estado de ordenação mutável viola a estrutura.

Min e Max dão o valor predefinido da API num conjunto vazio; GetViewBetween exige um intervalo válido.

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

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 set = new SortedSet<int> { 3, 1, 2 };
Console.WriteLine(string.Join(",", set));

Resultado

1,2,3

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

Fontes