Edit

Share via


Version Constructors

Definition

Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

Overloads

Version()

Initializes a new instance of the Version class.

Version(String)

Initializes a new instance of the Version class using the specified string.

Version(Int32, Int32)

Initializes a new instance of the Version class using the specified major and minor values.

Version(Int32, Int32, Int32)

Initializes a new instance of the Version class using the specified major, minor, and build values.

Version(Int32, Int32, Int32, Int32)

Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

Version()

Source:
Version.cs
Source:
Version.cs
Source:
Version.cs

Initializes a new instance of the Version class.

C#
public Version();

Remarks

This constructor creates a Version object with the following property values.

Property Value
Major 0
Minor 0
Build undefined (-1)
Revision undefined (-1)

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Version(String)

Source:
Version.cs
Source:
Version.cs
Source:
Version.cs

Initializes a new instance of the Version class using the specified string.

C#
public Version(string version);

Parameters

version
String

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

Exceptions

version has fewer than two components or more than four components.

version is null.

A major, minor, build, or revision component is less than zero.

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

At least one component of version represents a number greater than Int32.MaxValue.

Remarks

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

All defined components must be integers greater than or equal to 0. 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".

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Version(Int32, Int32)

Source:
Version.cs
Source:
Version.cs
Source:
Version.cs

Initializes a new instance of the Version class using the specified major and minor values.

C#
public Version(int major, int minor);

Parameters

major
Int32

The major version number.

minor
Int32

The minor version number.

Exceptions

major or minor is less than zero.

Remarks

This constructor creates a Version object with the following property values.

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Version(Int32, Int32, Int32)

Source:
Version.cs
Source:
Version.cs
Source:
Version.cs

Initializes a new instance of the Version class using the specified major, minor, and build values.

C#
public Version(int major, int minor, int build);

Parameters

major
Int32

The major version number.

minor
Int32

The minor version number.

build
Int32

The build number.

Exceptions

major, minor, or build is less than zero.

Remarks

This constructor creates a Version object with the following property values.

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Version(Int32, Int32, Int32, Int32)

Source:
Version.cs
Source:
Version.cs
Source:
Version.cs

Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

C#
public Version(int major, int minor, int build, int revision);

Parameters

major
Int32

The major version number.

minor
Int32

The minor version number.

build
Int32

The build number.

revision
Int32

The revision number.

Exceptions

major, minor, build, or revision is less than zero.

Examples

The following code example demonstrates the Version constructor, and Major, Minor, Build, Revision, MajorRevision, and MinorRevision properties.

C#
// 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

*/

Remarks

This constructor creates a Version object with the following property values.

Property Value
Major major
Minor minor
Build build
Revision revision

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0