CKTIS / C#
System.Collections.Generic.IComparer: praktická reference
System.Collections.Generic.IComparer: praktická reference: IComparer<T> určuje pořadí zápornou, nulovou nebo kladnou hodnotou vrácenou metodou Compare.
Verze: .NET API; verified on .NET 10.0.14
Syntaxe
System.Collections.Generic.IComparer /* select a documented member or constructor */IComparer určuje pořadí zápornou, nulovou nebo kladnou hodnotou vrácenou metodou Compare.
Použijte jej jako explicitní politiku řazení a pravidlo pořadí pro seřazené kolekce.
Porovnání musí být tranzitivní a konzistentní; neočekávejte přesně hodnoty minus jedna nebo jedna.
Compare(x,x) by mělo vrátit nulu a pořadí hodnot null je třeba zvolit vědomě.
Úplný program skutečně používá System.Collections.Generic.IComparer; přesně očekávaný stdout je True.
Pří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ýsledek
True
Úplný program skutečně používá `System.Collections.Generic.IComparer`; přesně očekávaný stdout je `True`.