C# Version CompareTo(Object)

Description

Version CompareTo(Object) compares the current Version object to a specified object and returns an indication of their relative values.

Syntax

Version.CompareTo(Object) has the following syntax.


public int CompareTo(
  Object version
)

Parameters

Version.CompareTo(Object) has the following parameters.

  • version - An object to compare, or null.

Returns

Version.CompareTo(Object) method returns A signed integer that indicates the relative values of the two objects, as shown in the following table. Return value Meaning Less than zero The current Version object is a version before version. Zero The current Version object is the same version as version. Greater than zero The current Version object is a version subsequent to version. -or- version is null.

Example


//  w  w  w  .j  a va  2 s  . c om
using System;

class Sample 
{
    public static void Main() 
    {
        Version interim = new Version(1,2,3,4);
        Version interim1 = new Version(1,2,4,4);
    
        Console.WriteLine(interim.CompareTo((object)interim1));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version