| by Arround The Web | No comments

Environment.Version Property

If you want to get the version of the system/machine using C#, use the Version property.

The Environment Class in C# provides an information about the working environment like variables, methods used, and system related information. It is possible to get the platform ID’s, Domain names, and check if the modifiers present in the C# application.Environment Class has a vast range of applications in C# and .NET. It mainly tells us the system information without checking manually.

Environment.Version

The Version Property in the Environment class returns the version that includes the major value, minor value, build value, and revision integer.

Syntax:

Version Environment.Version

Return Type:

Return the Version in the form of – major.minor.build.revision.

Use the corresponding syntax if you want to return the following:

  1. major – Environment.Version.Major
  2. minor – Environment.Version.Minor
  3. build – Environment.Version.Build
  4. revision – Environment.Version.Revision

Example 1:

Here, we return the Version.

using System;
class Linuxhint
{
    //let's implement the Version property inside main method
    static public  void Main()
    {
        //get the Version
        Console.WriteLine("Your current Platform Version is: "+Environment.Version);
    }
}

Output:

By seeing the previous output, the entire version is returned along with the major, minor, build, and revision separated by dot.

Explanation:

Line 5:

We implement our property inside the main() method.

Line 8:

Console.WriteLine(“Your current Platform Version is: “+Environment.Version);

Here, we directly use the Version property to return the version of the platform that we are using.

Example 2:

Here, we return the Version along with Major, Minor, Build, and Revision, separately.

using System;
class Linuxhint
{
    //let's implement the Version property inside main method
    static public  void Main()
    {
        //get the Version
        Console.WriteLine("Your current Platform Version is: "+Environment.Version);
        //get the major
        Console.WriteLine("Major: "+Environment.Version.Major);
         //get the minor
        Console.WriteLine("Minor: "+Environment.Version.Minor);
         //get the build
        Console.WriteLine("Build: "+Environment.Version.Build);
        //get the revision
        Console.WriteLine("Revision: "+Environment.Version.Revision);
    }
}

Output:

Explanation:

Line 8:

Console.WriteLine(“Your current Platform Version is: “+Environment.Version);

It returns the entire version.

Line 10:

C Console.WriteLine(“Major: “+Environment.Version.Major);

It returns the Major from the Version.

Line 12:

Console.WriteLine(“Minor: “+Environment.Version.Minor);;

It returns the Minor from the Version.

Line 14:

Console.WriteLine(“Build: “+Environment.Version.Build);

It returns the Build integer from the Version.

Line 16:

Console.WriteLine(“Revision: “+Environment.Version.Revision);

It returns the revision number from the Version.

Conclusion

The Version property in the Environment class is used to get the Version of the current platform in C#. It includes the Major, Minor, Build, and Revision separated by dot. It is also possible to get these separately. We discussed the two different examples to understand this concept better.

Share Button

Source: linuxhint.com

Leave a Reply