compare Summary Compares the UInteger16 object to another UInteger16 object. Usage public final Comparison compare(UInteger16 object) Returns A System.Comparison enumeration result representing whether the specified UInteger16 comparison object is less than, equal to, or greater than the current UInteger16 object. Parameters object The UInteger16 object to compare to. Description Compares the UInteger16 object to another UInteger16 object. Returns one of the following System.Comparison enumeration values: System.Comparison.LESS_THAN System.Comparison.EQUAL System.Comparison.GREATER_THAN Examples Basic Usage 12345import System; unsigned short b = 2;Comparison result = b.compare(2);Console.log(result == Comparison.EQUAL); Sorting 12345import System; unsigned short[] arr = [ 5, 1, 3, 2 ];arr.sort(); // 'System.Array<T>.sort' uses 'compare' to sort elementsConsole.log(arr.join(", ")); Custom Sort 1234567891011121314151617import System;import System.Assert; unsigned short[] arr = [ 5, 1, 3, 2 ];arr.sort(Comparison(unsigned short a, unsigned short b) { if (a < b) { return Comparison.LESS_THAN; } else if (a > b) { return Comparison.GREATER_THAN; } else { assert(a == b); return Comparison.EQUAL; }});Console.log(arr.join(", ")); Share HTML | BBCode | Direct Link