C# Program to Get the Machine Name or Host Name Using Environment Class Last Updated : 30 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information and time since last system boot in milliseconds information. By just using the predefined MachineName Property we can get the machine name or the hostname using the Environment class. This property is used to find the NetBIOS name of the computer. It also throws InvalidOperationException when this property does not get the name of the computer. Syntax: Environment.MachineName Return: This method returns a string that contains the machine name. Example: C# // C# program to find the name of the machine // Using Environment class using System; class GFG{ static public void Main() { // Here we get the machine name // Using the MachineName property // of the Environment class Console.WriteLine("Machine Name is" + Environment.MachineName); } } Output: Machine Name is Check Comment More infoAdvertise with us Next Article C# Program to Get Number of Processors of Current Machine using Environment Class S sravankumar_171fa07058 Follow Improve Article Tags : C# CSharp-programs Similar Reads C# Program to Get Number of Processors of Current Machine using Environment Class Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environme 1 min read C# Program to Get the Memory Size For OS Page File using Environment Class Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environme 2 min read C# Program to Get the Environment Variables Using Environment Class In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, 3 min read C# Program to Get the Path of System Directory Using Environment Class In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, 2 min read C# Program to Demonstrate the Use of GetCommandLineArgs() Method of Environment Class Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environme 3 min read C# Program to Get the Network Domain Name Associated with Current Using Environment Class In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, 2 min read Like