| 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
|
|
|
| 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.
| | Show full unit code | Monday compared to Friday = -1
Friday compared to Friday = 0
Friday compared to Monday = 1
|
| |
|
|
|