Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Version
Assembly: System.Runtime
Inheritance: object → Version
Implemented Interfaces
- ICloneable
- IComparable
- IComparable`1
- IEquatable`1
- ISpanFormattable (Inherits: IFormattable)
- IUtf8SpanFormattable
- IUtf8SpanParsable`1
Represents the version number of an assembly, operating system, or the common language runtime. This class cannot be inherited.
Properties
public
int
Build
Gets the value of the build component of the version number for the current <see cref="T:System.Version" /> object.
public
int
Major
Gets the value of the major component of the version number for the current <see cref="T:System.Version" /> object.
public
short
MajorRevision
Gets the high 16 bits of the revision number.
public
int
Minor
Gets the value of the minor component of the version number for the current <see cref="T:System.Version" /> object.
public
short
MinorRevision
Gets the low 16 bits of the revision number.
public
int
Revision
Gets the value of the revision component of the version number for the current <see cref="T:System.Version" /> object.
Methods
public
object
Clone​()
Returns a new <see cref="T:System.Version" /> object whose value is the same as the current <see cref="T:System.Version" /> object.
Returns A new <see cref="T:System.Object" /> whose values are a copy of the current <see cref="T:System.Version" /> object.
public
int
CompareTo​(object version)
Compares the current <see cref="T:System.Version" /> object to a specified object and returns an indication of their relative values.
Returns A signed integer that indicates the relative values of the two objects, as shown in the following table.
<list type="table">
<listheader>
<term> Return value</term>
<description> Meaning</description>
</listheader>
<item>
<term> Less than zero</term>
<description> The current <see cref="T:System.Version" /> object is a version before <paramref name="version" />.</description>
</item>
<item>
<term> Zero</term>
<description> The current <see cref="T:System.Version" /> object is the same version as <paramref name="version" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> The current <see cref="T:System.Version" /> object is a version subsequent to <paramref name="version" />, or <paramref name="version" /> is <see langword="null" />.</description>
</item>
</list>
version
An object to compare, or <see langword="null" /> .
public
int
CompareTo​(Version value)
Compares the current <see cref="T:System.Version" /> object to a specified <see cref="T:System.Version" /> object and returns an indication of their relative values.
Returns A signed integer that indicates the relative values of the two objects, as shown in the following table.
<list type="table">
<listheader>
<term> Return value</term>
<description> Meaning</description>
</listheader>
<item>
<term> Less than zero</term>
<description> The current <see cref="T:System.Version" /> object is a version before <paramref name="value" />.</description>
</item>
<item>
<term> Zero</term>
<description> The current <see cref="T:System.Version" /> object is the same version as <paramref name="value" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> The current <see cref="T:System.Version" /> object is a version subsequent to <paramref name="value" />, or <paramref name="value" /> is <see langword="null" />.</description>
</item>
</list>
value
A <see cref="T:System.Version" /> object to compare to the current <see cref="T:System.Version" /> object, or <see langword="null" /> .
public
bool
Equals​(object obj)
Returns a value indicating whether the current <see cref="T:System.Version" /> object is equal to a specified object.
Returns <see langword="true" /> if the current <see cref="T:System.Version" /> object and <paramref name="obj" /> are both <see cref="T:System.Version" /> objects, and every component of the current <see cref="T:System.Version" /> object matches the corresponding component of <paramref name="obj" /> ; otherwise, <see langword="false" /> .
obj
An object to compare with the current <see cref="T:System.Version" /> object, or <see langword="null" /> .
public
bool
Equals​(Version obj)
Returns a value indicating whether the current <see cref="T:System.Version" /> object and a specified <see cref="T:System.Version" /> object represent the same value.
Returns <see langword="true" /> if every component of the current <see cref="T:System.Version" /> object matches the corresponding component of the <paramref name="obj" /> parameter; otherwise, <see langword="false" /> .
obj
A <see cref="T:System.Version" /> object to compare to the current <see cref="T:System.Version" /> object, or <see langword="null" /> .
public
int
GetHashCode​()
Returns a hash code for the current <see cref="T:System.Version" /> object.
Returns A 32-bit signed integer hash code.
public static
Version
Parse​(ReadOnlySpan<​byte> utf8Text)
Converts the specified read-only span of UTF-8 characters that represents a version number to an equivalent Version object.
Returns An object that is equivalent to the version number specified in the <paramref name="utf8Text" /> parameter.
utf8Text
A read-only span of UTF-8 characters that contains a version number to convert.
public static
Version
Parse​(ReadOnlySpan<​char> input)
Converts the specified read-only span of characters that represents a version number to an equivalent <see cref="T:System.Version" /> object.
Returns An object that is equivalent to the version number specified in the <paramref name="input" /> parameter.
input
A read-only span of characters that contains a version number to convert.
public static
Version
Parse​(string input)
Converts the string representation of a version number to an equivalent <see cref="T:System.Version" /> object.
Returns An object that is equivalent to the version number specified in the <paramref name="input" /> parameter.
input
A string that contains a version number to convert.
public
string
ToString​()
Converts the value of the current <see cref="T:System.Version" /> object to its equivalent <see cref="T:System.String" /> representation.
Returns The <see cref="T:System.String" /> representation of the values of the major, minor, build, and revision components of the current <see cref="T:System.Version" /> object, 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 a <see cref="T:System.Version" /> object using the constructor <c>Version(1,1)</c> , the returned string is "1.1". If you create a <see cref="T:System.Version" /> object using the constructor <c>Version(1,3,4,2)</c> , the returned string is "1.3.4.2".
public
string
ToString​(int fieldCount)
Converts the value of the current <see cref="T:System.Version" /> object to its equivalent <see cref="T:System.String" /> representation. A specified count indicates the number of components to return.
Returns The <see cref="T:System.String" /> representation of the values of the major, minor, build, and revision components of the current <see cref="T:System.Version" /> object, each separated by a period character ('.'). The <paramref name="fieldCount" /> parameter determines how many components are returned.
<list type="table">
<listheader>
<term> fieldCount</term>
<description> Return Value</description>
</listheader>
<item>
<term> 0</term>
<description> An empty string ("").</description>
</item>
<item>
<term> 1</term>
<description> major</description>
</item>
<item>
<term> 2</term>
<description> major.minor</description>
</item>
<item>
<term> 3</term>
<description> major.minor.build</description>
</item>
<item>
<term> 4</term>
<description> major.minor.build.revision</description>
</item>
</list>
For example, if you create <see cref="T:System.Version" /> object using the constructor <c>Version(1,3,5)</c> , <c>ToString(2)</c> returns "1.3" and <c>ToString(4)</c> throws an exception.
fieldCount
The number of components to return. The <paramref name="fieldCount" /> ranges from 0 to 4.
public
bool
TryFormat​(Span<​byte> utf8Destination,
int fieldCount,
Int32& bytesWritten)
public
bool
TryFormat​(Span<​byte> utf8Destination,
Int32& bytesWritten)
public
bool
TryFormat​(Span<​char> destination,
int fieldCount,
Int32& charsWritten)
public static
bool
TryParse​(ReadOnlySpan<​byte> utf8Text,
Version&? result)
public static
bool
TryParse​(ReadOnlySpan<​char> input,
Version&? result)
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .