Home  |  Delphi .net Home  |  System.Enum  |  CompareTo Method
  
CompareTo  
Method  
Compare the current enum value to another enum
Enum Class
System NameSpace
NotCF1.  Function CompareTo ( Target : Object ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
Compares the current (source) value with the Target value. Returns one of the following values :
Source < Target Gives <0
Source = Target Gives  0
Source > Target Gives >0
The exact value is not guaranteed.
Notes
In the example, the two enums are defined as System.Enum types. If you replace the type with DayOfWeek, you will find that DayOfWeek does not support the CompareTo method.
Microsoft MSDN Links
System
System.Enum
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  Day1, Day2 : System.Enum;
  Result     : Integer;

begin
  Day1 := DayOfWeek.Monday;
  Day2 := DayOfWeek.Friday;

  Result := Day1.CompareTo(Day2);

  Console.WriteLine('{0} compared to {1} = {2}',
                    Day1.ToString,
                    Day2.ToString,
                    Result.ToString);

  Result := Day2.CompareTo(Day2);

  Console.WriteLine('{0} compared to {1} = {2}',
                    Day2.ToString,
                    Day2.ToString,
                    Result.ToString);

  Result := Day2.CompareTo(Day1);

  Console.WriteLine('{0} compared to {1} = {2}',
                    Day2.ToString,
                    Day1.ToString,
                    Result.ToString);

  Console.ReadLine;
end.
   Monday compared to Friday = -1
   Friday compared to Friday = 0
   Friday compared to Monday = 1
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author