Table of Contents

Class ComparisonComparer<T>

Namespace
ExControls
Assembly
ExControls.dll

Wraps a generic Comparison{T} delegate in an IComparer to make it easy to use a lambda expression for methods that take an IComparer or IComparer{T}

public class ComparisonComparer<T> : IComparer<T>, IComparer

Type Parameters

T

type of the compared objects

Inheritance
ComparisonComparer<T>
Implements
Inherited Members

Constructors

ComparisonComparer(Comparison<T>)

Initializes a new instance of the ComparisonComparer<T> class.

public ComparisonComparer(Comparison<T> comparison)

Parameters

comparison Comparison<T>

comparison used by the comparer

Methods

Compare(object?, object?)

Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

public int Compare(object? o1, object? o2)

Parameters

o1 object
o2 object

Returns

int

A signed integer that indicates the relative values of x and y:
- If less than 0, x is less than y.
- If 0, x equals y.
- If greater than 0, x is greater than y.

Exceptions

ArgumentException

Neither x nor y implements the IComparable interface.

-or-

x and y are of different types and neither one can handle comparisons with the other.

Compare(T?, T?)

Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

public int Compare(T? x, T? y)

Parameters

x T

The first object to compare.

y T

The second object to compare.

Returns

int

A signed integer that indicates the relative values of x and y, as shown in the following table.

Value Meaning
Less than zerox is less than y.
Zerox equals y.
Greater than zerox is greater than y.