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
Ttype of the compared objects
- Inheritance
-
ComparisonComparer<T>
- Implements
-
IComparer<T>
- Inherited Members
Constructors
ComparisonComparer(Comparison<T>)
Initializes a new instance of the ComparisonComparer<T> class.
public ComparisonComparer(Comparison<T> comparison)
Parameters
comparisonComparison<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
Returns
- int
A signed integer that indicates the relative values of
xandy:
- If less than 0,xis less thany.
- If 0,xequalsy.
- If greater than 0,xis greater thany.
Exceptions
- ArgumentException
Neither
xnoryimplements the IComparable interface.-or-
xandyare 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
xTThe first object to compare.
yTThe second object to compare.
Returns
- int
A signed integer that indicates the relative values of
xandy, as shown in the following table.Value Meaning Less than zero xis less thany.Zero xequalsy.Greater than zero xis greater thany.