Version 類別

定義

表示組件的版本號碼、作業系統或 Common Language Runtime。 此類別無法獲得繼承。

public ref class Version sealed : IComparable, IComparable<Version ^>, IEquatable<Version ^>
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>, ISpanFormattable
public ref class Version sealed : ICloneable, IComparable, IComparable<Version ^>, IEquatable<Version ^>, ISpanFormattable, IUtf8SpanFormattable
public ref class Version sealed : ICloneable, IComparable
public sealed class Version : IComparable, IComparable<Version>, IEquatable<Version>
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>, ISpanFormattable
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>, ISpanFormattable, IUtf8SpanFormattable
[System.Serializable]
public sealed class Version : ICloneable, IComparable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
type Version = class
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface ISpanFormattable
    interface IFormattable
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface IFormattable
    interface ISpanFormattable
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface IFormattable
    interface ISpanFormattable
    interface IUtf8SpanFormattable
type Version = class
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
    interface ICloneable
[<System.Serializable>]
type Version = class
    interface ICloneable
    interface IComparable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Version = class
    interface ICloneable
    interface IComparable
    interface IComparable<Version>
    interface IEquatable<Version>
Public NotInheritable Class Version
Implements IComparable, IComparable(Of Version), IEquatable(Of Version)
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version)
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version), ISpanFormattable
Public NotInheritable Class Version
Implements ICloneable, IComparable, IComparable(Of Version), IEquatable(Of Version), ISpanFormattable, IUtf8SpanFormattable
Public NotInheritable Class Version
Implements ICloneable, IComparable
繼承
Version
屬性
實作

範例

下列範例會 AssemblyVersionAttribute 使用 屬性,將版本號碼指派給元件。 在編譯時期,這個版本資訊會與元件的元數據一起儲存。 在運行時間,此範例Type.Assembly會擷取元件中找到之類型上的屬性值,以取得執行中元件的參考,並從方法所Assembly.GetName傳回物件的 屬性AssemblyName擷取元件的版本資訊Version

using System;
using System.Reflection;

[assembly:AssemblyVersionAttribute("2.0.1")]

public class Example1
{
   public static void Main()
   {
      Assembly thisAssem = typeof(Example1).Assembly;
      AssemblyName thisAssemName = thisAssem.GetName();
       
      Version ver = thisAssemName.Version;
       
      Console.WriteLine("This is version {0} of {1}.", ver, thisAssemName.Name);    
   }
}
// The example displays the following output:
//        This is version 2.0.1.0 of Example1.
open System.Reflection

[<assembly: AssemblyVersionAttribute "2.0.1">]
do ()

type Example1 = class end

let thisAssem = typeof<Example1>.Assembly
let thisAssemName = thisAssem.GetName()
   
let ver = thisAssemName.Version
   
printfn $"This is version {ver} of {thisAssemName.Name}."
// The example displays the following output:
//        This is version 2.0.1.0 of Example1.
Imports System.Reflection

<Assembly:AssemblyVersionAttribute("2.0.1")>
Module Example1
   Public Sub Main()
       Dim thisAssem As Assembly = GetType(Example1).Assembly
       Dim thisAssemName As AssemblyName = thisAssem.GetName()
       
       Dim ver As Version = thisAssemName.Version
       
       Console.WriteLine("This is version {0} of {1}.", ver, thisAssemName.Name)    
   End Sub
End Module
' The example displays the following output:
'      This is version 2.0.1.0 of Example1.

備註

如需此 API 的詳細資訊,請參閱 版本補充 API 備註

建構函式

Version()

初始化 Version 類別的新執行個體。

Version(Int32, Int32)

使用指定的主要和次要值,初始化 Version 類別的新執行個體。

Version(Int32, Int32, Int32)

使用指定的主要、次要和組建值,初始化 Version 類別的新執行個體。

Version(Int32, Int32, Int32, Int32)

使用指定的主要、次要、組建和修訂編號,初始化 Version 類別的新執行個體。

Version(String)

以指定的字串初始化 Version 類別的新執行個體。

屬性

Build

取得目前 Version 物件的版本號碼之組建元件值。

Major

取得目前 Version 物件的版本號碼之主要元件值。

MajorRevision

取得修訂編號的高 16 位元。

Minor

取得目前 Version 物件的版本號碼之次要元件值。

MinorRevision

取得修訂編號的低 16 位元。

Revision

取得目前 Version 物件的版本號碼之修訂元件值。

方法

Clone()

傳回新的 Version 物件,它的值和目前的 Version 物件相同。

CompareTo(Object)

將目前 Version 物件與指定物件相比較,並傳回其相對值的指示。

CompareTo(Version)

將目前 Version 物件與指定的 Version 物件相比較,並傳回其相對值的指示。

Equals(Object)

傳回值,指出目前的 Version 物件是否等於指定的物件。

Equals(Version)

傳回值,指出目前的 Version 物件和指定的 Version 物件是否表示相同的值。

GetHashCode()

傳回目前 Version 物件的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Parse(ReadOnlySpan<Char>)

轉換代表相當於 Version 物件版本號碼的指定字元唯讀延伸。

Parse(String)

將版本號碼的字串表示轉換為對等的 Version 物件。

ToString()

將目前 Version 物件的值轉換為它的對等 String 表示。

ToString(Int32)

將目前 Version 物件的值轉換為它的對等 String 表示。 指定的計數指示要傳回的元件數目。

TryFormat(Span<Byte>, Int32)

嘗試將此版本實例格式化為位元組範圍。

TryFormat(Span<Byte>, Int32, Int32)

嘗試將此版本實例格式化為位元組範圍。

TryFormat(Span<Char>, Int32)

嘗試將此版本執行個體格式化為字元延伸。

TryFormat(Span<Char>, Int32, Int32)

嘗試將此版本執行個體格式化為字元延伸。

TryParse(ReadOnlySpan<Char>, Version)

嘗試轉換代表相當於 Version 物件版本號碼的指定唯讀字元延伸,且傳回指出轉換是否成功的值。

TryParse(String, Version)

嘗試將版本號碼的字串表示轉換為對等的 Version 物件,並傳回表示轉換是否成功的值。

運算子

Equality(Version, Version)

判斷指定的兩個 Version 物件是否相等。

GreaterThan(Version, Version)

判斷第一個指定的 Version 物件是否大於第二個指定的 Version 物件。

GreaterThanOrEqual(Version, Version)

判斷第一個指定的 Version 物件是否大於或等於第二個指定的 Version 物件。

Inequality(Version, Version)

判斷指定的兩個 Version 物件是否相等。

LessThan(Version, Version)

判斷第一個指定的 Version 物件是否小於第二個指定的 Version 物件。

LessThanOrEqual(Version, Version)

判斷第一個指定的 Version 物件是否小於或等於第二個 Version 物件。

明確介面實作

IComparable.CompareTo(Object)

將目前 Version 物件與指定物件相比較,並傳回其相對值的指示。

IFormattable.ToString(String, IFormatProvider)

使用指定的格式,格式化目前執行個體的值。

ISpanFormattable.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前實例的值格式化為提供的字元範圍。

IUtf8SpanFormattable.TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前實例的值格式化為UTF-8到提供的位元組範圍。

適用於