C# - Environment.MachineName Property with Example

In this tutorial, we will learn about the C# Environment.MachineName property with its definition, usage, syntax, and example. By Nidhi Last updated : March 30, 2023

Environment.MachineName Property

The Environment.MachineName property is used to get the machine name or hostname.

Syntax

string Environment.MachineName

Parameter(s)

  • None

Return Value

This property returns string that contains the machine name.

C# Example of Environment.MachineName Property

The source code to get the Machine Name or Host Name using Environment class is given below. The given program is compiled and executed successfully.

using System;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        string machineName = Environment.MachineName;

        Console.WriteLine("Machine Name:");
        Console.WriteLine(machineName);
    }
}

Output

Machine Name:
NIDHI-PC
Press any key to continue . . .

C# Environment Class Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.