Hide

SftTree/NET 2.0 - Tree Control for Windows Forms

Display
Print

Compare Method, SortAscending Class

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

Class: SortAscending
Namespace: Softelvdm.SftTreeNET
Assembly: Softelvdm.SftTreeNET

Syntax

public int Compare(
    object x,
    object y );
Public Function Compare(
    ByVal x As Object,
    ByVal y As Object
  ) As Integer

Parameters

x

The first object to compare. This object can be cast into an ItemClass object.

y

The second object to compare. This object can be cast into an ItemClass object.

Return Value

The collating sequence. Return a value greater than zero to indicate that x is greater than y, equal to 0 to indicate that x and y are equal, a value less than zero to indicate x is less than y.

Comments

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

Examples

C#

        }

        public sealed class SortTagObjectAsLongAscending : IComparer {
            private int m_ColumnIndex;

            public SortTagObjectAsLongAscending(int ColumnIndex) {
                m_ColumnIndex = ColumnIndex;
            }
            public int Compare(object x, object y) {
                ItemClass i1 = (ItemClass)x;
                ItemClass i2 = (ItemClass)y;
                long l1 = (long) i1.Cells[m_ColumnIndex].TagObject;
                long l2 = (long) i2.Cells[m_ColumnIndex].TagObject;
                if (l1 > l2) return 1;
                if (l1 < l2) return -1;
                return 0;

VB.NET

Public NotInheritable Class SortTagObjectAsLongAscending
            Implements IComparer
    Private m_ColumnIndex As Integer

    Public Sub New(ByVal ColumnIndex As Integer)
        m_ColumnIndex = ColumnIndex
    End Sub
    Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
        Dim i1 As ItemClass = x
        Dim i2 As ItemClass = y
        Dim l1 As Long = i1.Cells(m_ColumnIndex).TagObject
        Dim l2 As Long = i2.Cells(m_ColumnIndex).TagObject
        If l1 > l2 Then Return 1
        If l1 < l2 Then Return -1
        Return 0
    End Function

See Also SortAscending Class | Classes | SftTree/NET 2.0