Windows.ApplicationModel.PackageVersion

Represents the version information for a package. This structure is used extensively throughout the Windows Runtime (WinRT) API to identify specific versions of applications, components, and resources.

Namespace

Windows.ApplicationModel

Assembly

Windows.Foundation.FoundationContract

Implemented By

Overview

The PackageVersion structure provides a standardized way to represent and compare software versions. It consists of four components: major, minor, build, and revision numbers. This structure is value type, meaning it is allocated on the stack and is immutable.

Syntax

public struct PackageVersion
{
    public ushort Major;
    public ushort Minor;
    public ushort Build;
    public ushort Revision;
}

Members

Properties

Name Type Description
Major ushort The major version number (e.g., 1 in 1.2.3.4).
Minor ushort The minor version number (e.g., 2 in 1.2.3.4).
Build ushort The build number (e.g., 3 in 1.2.3.4).
Revision ushort The revision number (e.g., 4 in 1.2.3.4).

Methods

Name Description
Equals(object obj) Determines whether the specified object is equal to the current object.
GetHashCode() Serves as the default hash function.
ToString() Returns a string that represents the current object. The format is typically "Major.Minor.Build.Revision".

Operators

PackageVersion supports equality operators (== and !=) for comparing two PackageVersion instances.

Remarks

When comparing two PackageVersion instances, the comparison proceeds from the Major component down to the Revision component. The first differing component determines which version is greater.

Example Usage

Here's how you might create and use a PackageVersion object:

using Windows.ApplicationModel;

// Create a PackageVersion instance
PackageVersion myVersion = new PackageVersion();
myVersion.Major = 2;
myVersion.Minor = 5;
myVersion.Build = 1000;
myVersion.Revision = 0;

// Convert to string
string versionString = myVersion.ToString(); // Outputs "2.5.1000.0"

// Compare versions
PackageVersion anotherVersion = new PackageVersion { Major = 2, Minor = 5, Build = 999, Revision = 1 };
if (myVersion > anotherVersion)
{
    // myVersion is newer
}

Related Topics