System.Version Class

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents the version number for a common language runtime assembly. This class cannot be inherited.
C# Syntax:
[Serializable]
public sealed class Version : ICloneable, IComparable
Remarks
Version numbers consist of two to four components: major, minor, build, and revision. Components major and minor are required. Components build and revision are optional, but the revision component is only optional if the build component is not defined. All defined components must be decimal integers greater than 0. Metadata restricts the major, minor, build, and revision components to a maximum value of UInt16.MaxValue - 1.

The format of the version number is as follows. Optional components are shown in square brackets ('[' and ']'):

major.minor[.build[.revision]]

The components are used by convention as follows:

Subsequent versions of an assembly that differ only by build or revision numbers are considered to be Quick Fix Engineering (QFE) updates of the prior version. If necessary, the build and revision numbers can be honored by changing the version policy in the configuration.

This class implements the ICloneable and IComparable interfaces.

See also:
System Namespace

System.Version Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the Version class.
ctor #2 Overloaded:
.ctor(string version)

Initializes a new instance of the Version class using the value represented by the specified String.
ctor #3 Overloaded:
.ctor(int major, int minor)

Initializes a new instance of the Version class using the specified major and minor values.
ctor #4 Overloaded:
.ctor(int major, int minor, int build)

Initializes a new instance of the Version class using the specified major, minor, and build values.
ctor #5 Overloaded:
.ctor(int major, int minor, int build, int revision)

Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.
Public Properties
Build Read-only

Gets the value of the build component of the version number for this instance.
Major Read-only

Gets the value of the major component of the version number for this instance.
Minor Read-only

Gets the value of the minor component of the version number for this instance.
Revision Read-only

Gets the value of the revision component of the version number for this instance.
Public Methods
Clone Returns a new Version whose value is the same as this instance.
CompareTo Compares this instance to a specified object and returns an indication of their relative values.
Equals Overridden:
Returns a value indicating whether this instance is equal to a specified object.
GetHashCode Overridden:
Returns a hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString Overloaded:
ToString()

Overridden:
Converts the value of this instance to its equivalent String representation.
ToString Overloaded:
ToString(int fieldCount)

Converts the value of this instance to its equivalent String representation. A specified count indicates the number of components to return.
Public Operators and Type Conversions
op_Equality Determines whether two specified instances of Version are equal.
op_GreaterThan Determines whether the first specified instance of Version is greater than the second specified instance of Version.
op_GreaterThanOrEqual Determines whether the first specified instance of Version is greater than or equal to the second instance of Version.
op_Inequality Determines whether two specified instances of Version are not equal.
op_LessThan Determines whether the first specified instance of Version is less than the second specified instance of Version.
op_LessThanOrEqual Determines whether the first specified instance of Version is less than or equal to the second instance of Version.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Version Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the Version class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public Version();

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the Version class using the value represented by the specified String.
C# Syntax:
public Version(
   string version
);
Parameters:

version

A string containing the major, minor, build, and revision numbers, where each number is delimited with a period character ('.').

Exceptions
Exception Type Condition
ArgumentException version has fewer than two components or more than four components.

-or-

At least one component of version does not parse to a decimal integer.

ArgumentNullException version is null.
ArgumentOutOfRangeException A major, minor, build, or revision component is less than zero.
Remarks
The version parameter can only contain components major, minor, build, and revision , in that order, and all separated by periods. There must be at least two components, and at most four. The first two components are assumed to be major and minor. The value of unspecified components is undefined.

The format of the version number is as follows. Optional components are shown in square brackets ('[' and ']'):

major.minor[.build[.revision]]

All defined components must be decimal integers greater than 0. Metadata restricts the value of each major, minor, build, and revision component to a maximum value of UInt16.MaxValue - 1.

For example, if the major number is 6, the minor number is 2, the build number is 1, and the revision number is 3, then version should be "6.2.1.3".

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the Version class using the specified major and minor values.
C# Syntax:
public Version(
   int major,
   int minor
);
Parameters:

major

The major version number.

minor

The minor version number.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException major or minor is less than zero.
Remarks
Metadata restricts major and minor to a maximum value of UInt16.MaxValue - 1.

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of the Version class using the specified major, minor, and build values.
C# Syntax:
public Version(
   int major,
   int minor,
   int build
);
Parameters:

major

The major version number.

minor

The minor version number.

build

The build number.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException major, minor, or build are less than zero.
Remarks
Metadata restricts major, minor, and build to a maximum value of UInt16.MaxValue - 1.

Return to top


Overloaded ctor #5
Summary
Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.
C# Syntax:
public Version(
   int major,
   int minor,
   int build,
   int revision
);
Parameters:

major

The major version number.

minor

The minor version number.

build

The build number.

revision

The revision number.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException major, minor, build, or revision are less than zero.
Remarks
Metadata restricts major, minor, build, and revision to a maximum of UInt16.MaxValue - 1.

Return to top


Property: Build (read-only)
Summary
Gets the value of the build component of the version number for this instance.
C# Syntax:
public int Build {get;}
Remarks
For example, if the version number is 6.2.1.3, the build number is 1. If the version number is 6.2, the build number is undefined.

Return to top


Property: Major (read-only)
Summary
Gets the value of the major component of the version number for this instance.
C# Syntax:
public int Major {get;}
Remarks
For example, if the version number is 6.2, the major version is 6.

Return to top


Property: Minor (read-only)
Summary
Gets the value of the minor component of the version number for this instance.
C# Syntax:
public int Minor {get;}
Remarks
For example, if the version number is 6.2, the minor version is 2.

Return to top


Property: Revision (read-only)
Summary
Gets the value of the revision component of the version number for this instance.
C# Syntax:
public int Revision {get;}
Remarks
For example, if the version number is 6.2.1.3, the revision number is 3. If the version number is 6.2, the revision number is undefined.

Return to top


Method: Clone()
Summary
Returns a new Version whose value is the same as this instance.
C# Syntax:
public object Clone();
Return Value:
A new Object whose values are a copy of this Version.
Implements:
ICloneable.Clone
Remarks
The Object returned by this method must be explicitly cast to a Version before it can be used as one.

Return to top


Method: CompareTo(
   object version
)
Summary
Compares this instance to a specified object and returns an indication of their relative values.
C# Syntax:
public int CompareTo(
   object version
);
Parameters:

version

An object to compare, or null.

Return Value:


Return Value Description
Less than zero This instance is before .
Zero This instance is the same as .
Greater than zero This instance is subsequent to version.
Exceptions
Exception Type Condition
ArgumentNullException version is null.
ArgumentException version is not of type Version.
Implements:
IComparable.CompareTo
Remarks
The components of Version in decreasing order of importance are: major, minor, build, and revision. An unknown component is assumed to be older than any known component.

For example:

See also:
Version.Equals

Return to top


Overridden Method: Equals(
   object obj
)
Summary
Returns a value indicating whether this instance is equal to a specified object.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

An object to compare with this instance, or null.

Return Value:
true if this instance and obj are both Version objects, and every component of this instance matches the corresponding component of obj; otherwise, false.
See also:
Version.CompareTo

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Version();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Returns a hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: op_Equality(
   Version v1,
   Version v2
)
Summary
Determines whether two specified instances of Version are equal.
C# Syntax:
public static bool operator ==(
   Version v1,
   Version v2
);
Parameters:

v1

The first instance of Version.

v2

The second instance of Version.

Return Value:
true if v1 equals v2; otherwise, false.
See also:
Version.Equals | Version.CompareTo

Return to top


Method: op_GreaterThan(
   Version v1,
   Version v2
)
Summary
Determines whether the first specified instance of Version is greater than the second specified instance of Version.
C# Syntax:
public static bool operator >(
   Version v1,
   Version v2
);
Parameters:

v1

The first instance of Version.

v2

The second instance of Version.

Return Value:
true if v1 is greater than v2; otherwise, false.
See also:
Version.Equals | Version.CompareTo

Return to top


Method: op_GreaterThanOrEqual(
   Version v1,
   Version v2
)
Summary
Determines whether the first specified instance of Version is greater than or equal to the second instance of Version.
C# Syntax:
public static bool operator >=(
   Version v1,
   Version v2
);
Parameters:

v1

The first instance of Version.

v2

The second instance of Version.

Return Value:
true if v1 is greater than or equal to v2; otherwise, false.
See also:
Version.Equals | Version.CompareTo

Return to top


Method: op_Inequality(
   Version v1,
   Version v2
)
Summary
Determines whether two specified instances of Version are not equal.
C# Syntax:
public static bool operator !=(
   Version v1,
   Version v2
);
Parameters:

v1

The first instance of Version.

v2

The second instance of Version.

Return Value:
true if v1 does not equal v2; otherwise, false.
See also:
Version.Equals | Version.CompareTo

Return to top


Method: op_LessThan(
   Version v1,
   Version v2
)
Summary
Determines whether the first specified instance of Version is less than the second specified instance of Version.
C# Syntax:
public static bool operator <(
   Version v1,
   Version v2
);
Parameters:

v1

The first instance of Version.

v2

The second instance of Version.

Return Value:
true if v1 is less than v2; otherwise, false.
See also:
Version.Equals | Version.CompareTo

Return to top


Method: op_LessThanOrEqual(
   Version v1,
   Version v2
)
Summary
Determines whether the first specified instance of Version is less than or equal to the second instance of Version.
C# Syntax:
public static bool operator <=(
   Version v1,
   Version v2
);
Parameters:

v1

The first instance of Version.

v2

The second instance of Version.

Return Value:
true if v1 is less than or equal to v2; otherwise, false.
See also:
Version.Equals | Version.CompareTo

Return to top


Overloaded Method: ToString()
Summary
Converts the value of this instance to its equivalent String representation.
C# Syntax:
public override string ToString();
Return Value:
The String representation of the values of the major, minor, build, and revision components of this instance, as depicted in the following format. Each component is separated by a period character ('.'). Square brackets ('[' and ']') indicate a component that will not appear in the return value if the component is not defined:

major.minor[.build[.revision]]

For example, if you create an instance of Version using the constructor Version(1,1) , the returned string is "1.1". If you create an instance of Version using the constructor Version(1,3,4,2) , the returned string is "1.3.4.2".

Return to top


Overloaded Method: ToString(
   int fieldCount
)
Summary
Converts the value of this instance to its equivalent String representation. A specified count indicates the number of components to return.
C# Syntax:
public string ToString(
   int fieldCount
);
Parameters:

fieldCount

The number of components to return. The fieldCount ranges from 0 to 4.

Return Value:
The String representation of the values of the major, minor, build, and revision components of this instance, each separated by a period character ('.'). The fieldCount parameter determines how many components are returned.

fieldCount Return Value
0 An empty string ("").
1 major
2 major.minor
3 major.minor.build
4 major.minor.build.revision

For example, if you create an instance of Version using the constructor Version(1,3,5) , ToString(2) returns "1.3" and ToString(4) throws an exception.

Exceptions
Exception Type Condition
ArgumentException fieldCount is less than 0, or more than 4.

-or-

fieldCount is more than the number of components defined in this instance.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.