Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Collections.Generic.IComparer: praktická referencia

System.Collections.Generic.IComparer: praktická referencia: IComparer<T> určuje poradie zápornou, nulovou alebo kladnou hodnotou vrátenou metódou Compare.

Verzia: .NET API; verified on .NET 10.0.14

Syntax

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

IComparer určuje poradie zápornou, nulovou alebo kladnou hodnotou vrátenou metódou Compare.

Použite ho ako explicitnú politiku triedenia a pravidlo poradia pre zoradené kolekcie.

Porovnanie musí byť tranzitívne a konzistentné; neočakávajte presne hodnoty mínus jedna alebo jedna.

Compare(x,x) by malo vrátiť nulu a poradie hodnôt null treba zvoliť vedome.

Úplný program skutočne používa System.Collections.Generic.IComparer; presne očakávaný stdout je True.

Príklady

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;

IComparer<string> comparer = StringComparer.OrdinalIgnoreCase;
Console.WriteLine(comparer.Compare("a", "B") < 0);

Výsledok

True

Úplný program skutočne používa `System.Collections.Generic.IComparer`; presne očakávaný stdout je `True`.

Zdroje