CompareTo Method
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Compares the value of this instance to a specified object that contains a specified DateTime value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Function CompareTo ( _
val As Object _
) As Integer
public int CompareTo(
Object val
)
public:
int CompareTo(
Object^ val
)
member CompareTo :
val:Object -> int
public function CompareTo(
val : Object
) : int
Parameters
- val
Type: System. . :: . .Object
A boxed object to compare, or nullNothingnullptrunita null reference (Nothing in Visual Basic).
Return Value
Type: System. . :: . .Int32
A signed number indicating the relative values of this instance and value.
Value |
Description |
---|---|
Less than zero |
This instance is earlier than val. |
Zero |
This instance is the same as val. |
Greater than zero |
This instance is later than val, or val is nullNothingnullptrunita null reference (Nothing in Visual Basic). |
Exceptions
Exception | Condition |
---|---|
ArgumentException | val is not a DateTime. |
Remarks
Before comparing DateTime objects, make sure that the objects represent times in the same time zone. You can do this by comparing the values of their Kind properties.
Any instance of DateTime, regardless of its value, is considered greater than null Nothing nullptr unit a null reference (Nothing in Visual Basic) .
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.