Class ElementComparer<T>
Element-at-position comparer.
Implements
System.Collections.Generic.IComparer<T[]>
System.Collections.Generic.IEqualityComparer<T[]>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Numerics.Comparers
Assembly: Mars.Numerics.dll
Syntax
public class ElementComparer<T> : IComparer<T[]>, IEqualityComparer<T[]> where T : IComparable, IEquatable<T>
Type Parameters
Name | Description |
---|---|
T |
Remarks
This class compares arrays by checking the value
of a particular element at a given array index.
Examples
// We sort the arrays according to the
// elements at their second column.
double[][] values =
{ // v
new double[] { 0, 3, 0 },
new double[] { 0, 4, 1 },
new double[] { -1, 1, 1 },
new double[] { -1, 5, 4 },
new double[] { -2, 2, 6 },
};
// Sort the array considering only the second column
Array.Sort(values, new ElementComparer() { Index = 1 });
// The result will be
double[][] result =
{
new double[] { -1, 1, 1 },
new double[] { -2, 2, 6 },
new double[] { 0, 3, 0 },
new double[] { 0, 4, 1 },
new double[] { -1, 5, 4 },
};
Properties
| Improve this Doc View SourceIndex
Gets or sets the element index to compare.
Declaration
public int Index { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
This class compares arrays by checking the value
of a particular element at a given array index.
See Also
Methods
| Improve this Doc 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 |
Remarks
This class compares arrays by checking the value
of a particular element at a given array index.
See Also
| Improve this Doc View SourceEquals(T[], T[])
Determines whether two instances are equal.
Declaration
public bool Equals(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.Boolean |
true if the specified object is equal to the other; otherwise, false .
|
Remarks
This class compares arrays by checking the value
of a particular element at a given array index.
See Also
| Improve this Doc View SourceGetHashCode(T[])
Returns a hash code for a given instance.
Declaration
public int GetHashCode(T[] obj)
Parameters
Type | Name | Description |
---|---|---|
T[] | obj | The instance. |
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the instance, suitable for use in hashing algorithms and data structures like a hash table. |
Remarks
This class compares arrays by checking the value
of a particular element at a given array index.
See Also
Implements
System.Collections.Generic.IComparer<T>
System.Collections.Generic.IEqualityComparer<T>