Class ElementComparer
Element-at-position comparer.
Implements
System.Collections.Generic.IComparer<System.Double[]>
System.Collections.Generic.IEqualityComparer<System.Double[]>
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 : ElementComparer<double>, IComparer<double[]>, IEqualityComparer<double[]>
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 },
};
Implements
System.Collections.Generic.IComparer<T>
System.Collections.Generic.IEqualityComparer<T>