Class GeneralComparer<T>
General comparer which supports multiple sorting directions.
Inheritance
System.Object
GeneralComparer<T>
Namespace: ISynergy.Framework.Mathematics.Comparers
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public class GeneralComparer<T> : IComparer<T> where T : IComparable<T>
Type Parameters
Name | Description |
---|---|
T |
Examples
// Assume we have values to sort
double[] values = { 0, -5, 3, 1, 8 };
// We can create an ad-hoc sorting rule
Array.Sort(values, new GeneralComparer<double>(ComparerDirection.Descending));
// Result will be { 8, 5, 3, 1, 0 }.
Constructors
View SourceGeneralComparer(ComparerDirection)
Constructs a new General Comparer.
Declaration
public GeneralComparer(ComparerDirection direction)
Parameters
Type | Name | Description |
---|---|---|
ComparerDirection | direction | The direction to compare. |
Properties
View SourceDirection
Gets or sets the sorting direction used by this comparer.
Declaration
public ComparerDirection Direction { get; set; }
Property Value
Type | Description |
---|---|
ComparerDirection |
Methods
View SourceCompare(T, T)
Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Declaration
public int Compare(T x, T y)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
Returns
Type | Description |
---|---|
System.Int32 |
Extension Methods
CollectionExtensions.FromHierarchy<TSource>(TSource, Func<TSource, TSource>, Func<TSource, Boolean>)