Mono Class Library: System.Version Overview | MembersSystem.Version.CompareTo Method |
Returns the sort order of the current instance compared to the specified object. [Edit]
|
The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to version. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
Return Value Description A negative number Current instance < version. Zero Current instance == version. A positive number Current instance > version, or version is a null reference.
[Edit]
Type Reason ArgumentException version is not a Version and is not a null reference [Edit]
Note:[Edit]The components of Version in decreasing order of importance are: major, minor, build, and revision. An undefined component is assumed to be older than any defined component.
This method is implemented to support the IComparable interface.
C# Example using System; class VersionTest { static string Test ( Version v1, Version v2 ) { int i = v1.CompareTo(v2); if ( i < 0 ) return "older than"; else if ( i == 0 ) return "the same as"; else return "newer than"; } public static void Main() { Version vers1 = new Version( "6.1.2.4" ); Version vers2 = new Version( 6, 1 ); Version vers3 = new Version( 6, 1, 3 ); Console.Write("Version {0} is {1} ", vers1, Test(vers1, vers2)); Console.WriteLine("version {0}", vers2); Console.Write("Version {0} is {1} ", vers1, Test(vers1, vers3)); Console.WriteLine("version {0}", vers3); Console.Write("Version {0} is {1} ", vers3, Test(vers3, vers3)); Console.WriteLine("version {0}", vers3); Console.Write("Version {0} is {1} ", vers2, Test(vers2, vers1)); Console.WriteLine("version {0}", vers1); } }The output is
Version 6.1.2.4 is newer than version 6.1
Version 6.1.2.4 is older than version 6.1.3
Version 6.1.3 is the same as version 6.1.3
Version 6.1 is older than version 6.1.2.4
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0