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]]

所有定义的组件都必须是大于或等于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

适用于