Version 建構函式

定義

使用指定的主要、次要、組建和修訂編號,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

多載

Version()

初始化 Version 類別的新執行個體。Initializes a new instance of the Version class.

Version(String)

以指定的字串初始化 Version 類別的新執行個體。Initializes a new instance of the Version class using the specified string.

Version(Int32, Int32)

使用指定的主要和次要值,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class using the specified major and minor values.

Version(Int32, Int32, Int32)

使用指定的主要、次要和組建值,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class using the specified major, minor, and build values.

Version(Int32, Int32, Int32, Int32)

使用指定的主要、次要、組建和修訂編號,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

Version()

初始化 Version 類別的新執行個體。Initializes a new instance of the Version class.

public:
 Version();
public Version ();
Public Sub New ()

備註

此函式會建立具有下列屬性值的 Version 物件。This constructor creates a Version object with the following property values.

屬性Property Value
Major 00
Minor 00
Build undefined (-1)undefined (-1)
Revision undefined (-1)undefined (-1)

Version(String)

以指定的字串初始化 Version 類別的新執行個體。Initializes a new instance of the Version class using the specified string.

public:
 Version(System::String ^ version);
public Version (string version);
new Version : string -> Version
Public Sub New (version As String)

參數

version
String

包含主要、次要、組建和修訂編號的字串,其中每個編號以句號字元 ('.') 隔開。A string containing the major, minor, build, and revision numbers, where each number is delimited with a period character ('.').

例外狀況

version 具有兩個以下的元件或四個以上的元件。version has fewer than two components or more than four components.

versionnullversion is null.

主要、次要、組建或修訂元件小於零。A major, minor, build, or revision component is less than zero.

至少有一個 version 的元件未剖析成整數。At least one component of version does not parse to an integer.

至少有一個 version 的元件表示大於 MaxValue 的數字。At least one component of version represents a number greater than MaxValue.

備註

version 參數只能包含主要、次要、組建和修訂的元件,以及該順序,並以句點分隔所有。The version parameter can contain only the 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]]major.minor[.build[.revision]]

所有已定義的元件都必須是大於或等於0的整數。All defined components must be integers greater than or equal to 0. 例如,如果主要數位是6,次要數位是2,組建編號是1,修訂編號是3,則 version 應該是 "6.2.1.3"。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".

Version(Int32, Int32)

使用指定的主要和次要值,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class using the specified major and minor values.

public:
 Version(int major, int minor);
public Version (int major, int minor);
new Version : int * int -> Version
Public Sub New (major As Integer, minor As Integer)

參數

major
Int32

主要版本號碼。The major version number.

minor
Int32

次要版本號碼。The minor version number.

例外狀況

majorminor 小於零。major or minor is less than zero.

備註

此函式會建立具有下列屬性值的 Version 物件。This constructor creates a Version object with the following property values.

屬性Property Value
Major major
Minor minor
Build undefined (-1)undefined (-1)
Revision undefined (-1)undefined (-1)

Version(Int32, Int32, Int32)

使用指定的主要、次要和組建值,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class using the specified major, minor, and build values.

public:
 Version(int major, int minor, int build);
public Version (int major, int minor, int build);
new Version : int * int * int -> Version
Public Sub New (major As Integer, minor As Integer, build As Integer)

參數

major
Int32

主要版本號碼。The major version number.

minor
Int32

次要版本號碼。The minor version number.

build
Int32

組建編號。The build number.

例外狀況

majorminorbuild 小於零。major, minor, or build is less than zero.

備註

此函式會建立具有下列屬性值的 Version 物件。This constructor creates a Version object with the following property values.

屬性Property Value
Major major
Minor minor
Build build
Revision undefined (-1)undefined (-1)

Version(Int32, Int32, Int32, Int32)

使用指定的主要、次要、組建和修訂編號,初始化 Version 類別的新執行個體。Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

public:
 Version(int major, int minor, int build, int revision);
public Version (int major, int minor, int build, int revision);
new Version : int * int * int * int -> Version
Public Sub New (major As Integer, minor As Integer, build As Integer, revision As Integer)

參數

major
Int32

主要版本號碼。The major version number.

minor
Int32

次要版本號碼。The minor version number.

build
Int32

組建編號。The build number.

revision
Int32

修訂編號。The revision number.

例外狀況

majorminorbuildrevision 小於零。major, minor, build, or revision is less than zero.

範例

下列程式碼範例示範 Version 的函式,以及 MajorMinorBuildRevisionMajorRevisionMinorRevision 屬性。The following code example demonstrates the Version constructor, and Major, Minor, Build, Revision, MajorRevision, and MinorRevision properties.

// This example demonstrates the Version.Revision,
// MajorRevision, and MinorRevision properties.
using namespace System;

int main()
{
    String^ formatStandard = "Standard version:\n" +
        " major.minor.build.revision = {0}.{1}.{2}.{3}";
    String^ formatInterim = "Interim version:\n" +
        " major.minor.build.majRev/minRev = {0}.{1}.{2}.{3}/{4}";

    Version^ standardVersion = gcnew Version(2, 4, 1128, 2);
    Version^ interimVersion = gcnew Version(2, 4, 1128, (100 << 16) + 2);

    Console::WriteLine(formatStandard, standardVersion->Major, 
        standardVersion->Minor, standardVersion->Build, 
        standardVersion->Revision);
    Console::WriteLine(formatInterim, interimVersion->Major,
        interimVersion->Minor, interimVersion->Build, 
        interimVersion->MajorRevision, interimVersion->MinorRevision);
};
/*
This code example produces the following results:

Standard version:
major.minor.build.revision = 2.4.1128.2
Interim version:
major.minor.build.majRev/minRev = 2.4.1128.100/2

*/
// This example demonstrates the Version.Revision,
// MajorRevision, and MinorRevision properties.
using System;

class Sample 
{
    public static void Main() 
    {

    string fmtStd = "Standard version:\n" +
                    "  major.minor.build.revision = {0}.{1}.{2}.{3}";
    string fmtInt = "Interim version:\n" +
                    "  major.minor.build.majRev/minRev = {0}.{1}.{2}.{3}/{4}";

    Version std = new Version(2, 4, 1128, 2);
    Version interim = new Version(2, 4, 1128, (100 << 16) + 2);

    Console.WriteLine(fmtStd, std.Major, std.Minor, std.Build, std.Revision);
    Console.WriteLine(fmtInt, interim.Major, interim.Minor, interim.Build, 
                              interim.MajorRevision, interim.MinorRevision);
    }
}
/*
This code example produces the following results:

Standard version:
  major.minor.build.revision = 2.4.1128.2
Interim version:
  major.minor.build.majRev/minRev = 2.4.1128.100/2

*/
' This example demonstrates the Version.Revision,
' MajorRevision, and MinorRevision properties.

Class Sample
    Public Shared Sub Main() 
        Dim fmtStd As String = "Standard version:" & vbCrLf & _
                               "  major.minor.build.revision = {0}.{1}.{2}.{3}"
        Dim fmtInt As String = "Interim version:" & vbCrLf & _
                               "  major.minor.build.majRev/minRev = {0}.{1}.{2}.{3}/{4}"
        
        Dim std As New Version(2, 4, 1128, 2)
        Dim interim As New Version(2, 4, 1128, (100 << 16) + 2)
        
        Console.WriteLine(fmtStd, std.Major, std.Minor, std.Build, std.Revision)
        Console.WriteLine(fmtInt, interim.Major, interim.Minor, interim.Build, _
                          interim.MajorRevision, interim.MinorRevision)
    End Sub
End Class

'
'This code example produces the following results:
'
'Standard version:
'  major.minor.build.revision = 2.4.1128.2
'Interim version:
'  major.minor.build.majRev/minRev = 2.4.1128.100/2
'

備註

此函式會建立具有下列屬性值的 Version 物件。This constructor creates a Version object with the following property values.

屬性Property Value
Major major
Minor minor
Build build
Revision revision

適用於