A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-version below:

System.Version class - .NET | Microsoft Learn

This article provides supplementary remarks to the reference documentation for this API.

The Version class represents the version number of an assembly, operating system, or the common language runtime. Version numbers consist of two to four components: major, minor, build, and revision. The major and minor components are required; the build and revision components are optional, but the build component is required if the revision component is defined. All defined components must be integers greater than or equal to 0. The format of the version number is as follows (optional components are shown in square brackets):

major.minor[.build[.revision]]

The components are used by convention as follows:

Subsequent versions of an assembly that differ only by build or revision numbers are considered to be Hotfix updates of the prior version.

Important

The value of Version properties that have not been explicitly assigned a value is undefined (-1).

The MajorRevision and MinorRevision properties enable you to identify a temporary version of your application that, for example, corrects a problem until you can release a permanent solution. Furthermore, the Windows NT operating system uses the MajorRevision property to encode the service pack number.

Assign version information to assemblies

Ordinarily, the Version class is not used to assign a version number to an assembly. Instead, the AssemblyVersionAttribute class is used to define an assembly's version, as illustrated by the example in this article.

Retrieve version information

Version objects are most frequently used to store version information about some system or application component (such as the operating system), the common language runtime, the current application's executable, or a particular assembly. The following examples illustrate some of the most common scenarios:

Compare version objects

You can use the CompareTo method to determine whether one Version object is earlier than, the same as, or later than a second Version object. The following example indicates that Version 2.1 is later than Version 2.0.

Version v1 = new Version(2, 0);
Version v2 = new Version("2.1");
Console.Write("Version {0} is ", v1);
switch(v1.CompareTo(v2))
{
   case 0:
      Console.Write("the same as");
      break;
   case 1:
      Console.Write("later than");
      break;
   case -1:
      Console.Write("earlier than");
      break;
}
Console.WriteLine($" Version {v2}.");                  
// The example displays the following output:
//       Version 2.0 is earlier than Version 2.1.
open System

let v1 = Version(2, 0)
let v2 = Version "2.1"

printf $"Version {v1} is "

match v1.CompareTo v2 with
| 0 -> printf "the same as"
| 1 -> printf "later than"
| _ -> printf "earlier than"

printf $" Version {v2}."
// The example displays the following output:
//       Version 2.0 is earlier than Version 2.1.
Dim v1 As New Version(2,0)
Dim v2 As New Version("2.1")
Console.Write("Version {0} is ", v1)
Select Case v1.CompareTo(v2)
   Case 0
      Console.Write("the same as")
   Case 1
      Console.Write("later than")
   Case -1
      Console.Write("earlier than")
End Select
Console.WriteLine(" Version {0}.", v2)                  
' The example displays the following output:
'       Version 2.0 is earlier than Version 2.1.

For two versions to be equal, the major, minor, build, and revision numbers of the first Version object must be identical to those of the second Version object. If the build or revision number of a Version object is undefined, that Version object is considered to be earlier than a Version object whose build or revision number is equal to zero. The following example illustrates this by comparing three Version objects that have undefined version components.

using System;

enum VersionTime {Earlier = -1, Same = 0, Later = 1 };

public class Example2
{
   public static void Main()
   {
      Version v1 = new Version(1, 1);
      Version v1a = new Version("1.1.0");
      ShowRelationship(v1, v1a);
      
      Version v1b = new Version(1, 1, 0, 0);
      ShowRelationship(v1b, v1a);
   }

   private static void ShowRelationship(Version v1, Version v2)
   {
      Console.WriteLine($"Relationship of {v1} to {v2}: {(VersionTime) v1.CompareTo(v2)}");       
   }
}
// The example displays the following output:
//       Relationship of 1.1 to 1.1.0: Earlier
//       Relationship of 1.1.0.0 to 1.1.0: Later
open System

type VersionTime =
    | Earlier = -1
    | Same = 0
    | Later = 1

let showRelationship (v1: Version) (v2: Version) =
    printfn $"Relationship of {v1} to {v2}: {v1.CompareTo v2 |> enum<VersionTime>}" 

let v1 = Version(1, 1)
let v1a = Version "1.1.0"
showRelationship v1 v1a

let v1b = Version(1, 1, 0, 0)
showRelationship v1b v1a

// The example displays the following output:
//       Relationship of 1.1 to 1.1.0: Earlier
//       Relationship of 1.1.0.0 to 1.1.0: Later
Public Enum VersionTime
   Earlier = -1
   Same = 0
   Later = 1
End Enum

Module Example2
    Public Sub Main()
        Dim v1 As New Version(1, 1)
        Dim v1a As New Version("1.1.0")
        ShowRelationship(v1, v1a)

        Dim v1b As New Version(1, 1, 0, 0)
        ShowRelationship(v1b, v1a)
    End Sub

    Private Sub ShowRelationship(v1 As Version, v2 As Version)
        Console.WriteLine("Relationship of {0} to {1}: {2}",
                        v1, v2, CType(v1.CompareTo(v2), VersionTime))
    End Sub
End Module
' The example displays the following output:
'       Relationship of 1.1 to 1.1.0: Earlier
'       Relationship of 1.1.0.0 to 1.1.0: Later

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4