System.Version Class

Namespace: System
Represents the version of an assembly, an executable file, or the common language runtime.

Syntax

public sealed class Version : System.ICloneable, System.IComparable, System.IComparable<System.Version>, System.IEquatable<System.Version>

Remarks

The Version class represents version numbers as a sequence of integers. A version number consists of components such as major, minor, build, and revision. The Version class provides methods for parsing, comparing, and formatting version numbers.

Constructors

Name Description
Version() Initializes a new instance of the Version class. The default version is 0.0.0.0.
Version(int major) Initializes a new instance of the Version class with the specified major version.
Version(int major, int minor) Initializes a new instance of the Version class with the specified major and minor versions.
Version(int major, int minor, int build) Initializes a new instance of the Version class with the specified major, minor, and build versions.
Version(int major, int minor, int build, int revision) Initializes a new instance of the Version class with the specified major, minor, build, and revision versions.
Version(string version) Initializes a new instance of the Version class using the specified string representation.

Properties

Name Description
Build Gets the build number of the version.
MajorRevision Gets the major revision number of the version.
Major Gets the major version number of the version.
Minor Gets the minor version number of the version.
MinorRevision Gets the minor revision number of the version.
Revision Gets the revision number of the version.
Length Gets the number of components in the version number.

Methods

Name Description
Clone() Creates a new Version object from the current Version object.
CompareTo(object version) Compares the current Version object to another object.
CompareTo(Version value) Compares the current Version object to another Version object.
Equals(object obj) Determines whether the current Version object is equal to another object.
Equals(Version obj) Determines whether the current Version object is equal to another Version object.
GetHashCode() Returns the hash code for the current Version object.
Parse(string version) Converts the specified string representation of a version number to its Version equivalent.
op_Equality(Version left, Version right) Compares two Version objects for equality.
op_Inequality(Version left, Version right) Compares two Version objects for inequality.
op_GreaterThan(Version left, Version right) Compares two Version objects to determine if the first is greater than the second.
op_GreaterThanOrEqual(Version left, Version right) Compares two Version objects to determine if the first is greater than or equal to the second.
op_LessThan(Version left, Version right) Compares two Version objects to determine if the first is less than the second.
op_LessThanOrEqual(Version left, Version right) Compares two Version objects to determine if the first is less than or equal to the second.
ToString() Returns a string representation of the current Version object.
ToString(int fieldCount) Returns a string representation of the current Version object, using the specified number of components.
TryParse(string version, out Version result) Tries to convert the string representation of a version number to its Version equivalent.
TryParse(string version, System.Globalization.NumberStyles styles, System.IFormatProvider provider, out Version result) Tries to convert the string representation of a version number to its Version equivalent using specified styles and format provider.

Version() Constructor

public Version()

Initializes a new instance of the Version class. The default version is 0.0.0.0.

Version(int major) Constructor

public Version(int major)

Initializes a new instance of the Version class with the specified major version. The minor, build, and revision numbers default to 0.

Version(int major, int minor) Constructor

public Version(int major, int minor)

Initializes a new instance of the Version class with the specified major and minor versions. The build and revision numbers default to 0.

Version(int major, int minor, int build) Constructor

public Version(int major, int minor, int build)

Initializes a new instance of the Version class with the specified major, minor, and build versions. The revision number defaults to 0.

Version(int major, int minor, int build, int revision) Constructor

public Version(int major, int minor, int build, int revision)

Initializes a new instance of the Version class with the specified major, minor, build, and revision versions.

[System.Security.SecuritySafeCritical]

Version(string version) Constructor

public Version(string version)

Initializes a new instance of the Version class using the specified string representation.

[System.Security.SecuritySafeCritical]

Build Property

public int Build { get; }

Gets the build number of the version.

MajorRevision Property

public int MajorRevision { get; }

Gets the major revision number of the version.

Major Property

public int Major { get; }

Gets the major version number of the version.

Minor Property

public int Minor { get; }

Gets the minor version number of the version.

MinorRevision Property

public int MinorRevision { get; }

Gets the minor revision number of the version.

Revision Property

public int Revision { get; }

Gets the revision number of the version.

Length Property

public int Length { get; }

Gets the number of components in the version number.

Clone() Method

public object Clone()

Creates a new Version object from the current Version object.

[System.Security.SecuritySafeCritical]

CompareTo(object version) Method

public int CompareTo(object version)

Compares the current Version object to another object and returns an integer that indicates whether the current object precedes, follows, or occurs in the same position in sort order as the compared object.

CompareTo(Version value) Method

public int CompareTo(Version value)

Compares the current Version object to another Version object and returns an integer that indicates whether the current object precedes, follows, or occurs in the same position in sort order as the compared object.

Equals(object obj) Method

public override bool Equals(object obj)

Determines whether the current Version object is equal to another object.

Equals(Version obj) Method

public bool Equals(Version obj)

Determines whether the current Version object is equal to another Version object.

GetHashCode() Method

public override int GetHashCode()

Returns the hash code for the current Version object.

Parse(string version) Method

public static Version Parse(string version)

Converts the specified string representation of a version number to its Version equivalent.

[System.Security.SecuritySafeCritical]

op_Equality(Version left, Version right) Operator

public static bool operator ==(Version left, Version right)

Compares two Version objects for equality.

op_Inequality(Version left, Version right) Operator

public static bool operator !=(Version left, Version right)

Compares two Version objects for inequality.

op_GreaterThan(Version left, Version right) Operator

public static bool operator >(Version left, Version right)

Compares two Version objects to determine if the first is greater than the second.

op_GreaterThanOrEqual(Version left, Version right) Operator

public static bool operator >=(Version left, Version right)

Compares two Version objects to determine if the first is greater than or equal to the second.

op_LessThan(Version left, Version right) Operator

public static bool operator <(Version left, Version right)

Compares two Version objects to determine if the first is less than the second.

op_LessThanOrEqual(Version left, Version right) Operator

public static bool operator <=(Version left, Version right)

Compares two Version objects to determine if the first is less than or equal to the second.

ToString() Method

public override string ToString()

Returns a string representation of the current Version object.

ToString(int fieldCount) Method

public string ToString(int fieldCount)

Returns a string representation of the current Version object, using the specified number of components.

[System.Security.SecuritySafeCritical]

TryParse(string version, out Version result) Method

public static bool TryParse(string version, out Version result)

Tries to convert the string representation of a version number to its Version equivalent. Returns true if the conversion is successful; otherwise, false.

[System.Security.SecuritySafeCritical]

TryParse(string version, System.Globalization.NumberStyles styles, System.IFormatProvider provider, out Version result) Method

public static bool TryParse(string version, System.Globalization.NumberStyles styles, System.IFormatProvider provider, out Version result)

Tries to convert the string representation of a version number to its Version equivalent using specified styles and format provider. Returns true if the conversion is successful; otherwise, false.

[System.Security.SecuritySafeCritical]