compare Summary Defines how objects can be compared. Usage Comparison compare(T obj) Parameters obj The object to compare to. Description Defines how objects can be compared (with a "less than", "greater than", or "equal to" relationship). Only objects that can be compared can be sorted. Examples Comparison of Employees by Age 1234567891011121314151617181920212223242526import System; class Employee : IComparable<Employee>{ private unsigned int age; private string firstName; private string lastName; public Employee(string firstName, string lastName, unsigned int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } public Comparison compare(Employee that) { // Sort by employee age using System.UInteger32.compare return this.age.compare(that.age); }} Employee john = new Employee("John", "Smith", 52);Employee jane = new Employee("Jane", "Doe", 32); if (john.compare(jane) == Comparison.GREATER_THAN) { Console.log("John is older than Jane.");} Share HTML | BBCode | Direct Link