How to get the Computer Name in C# ?

Published on February 8, 2016 by abundantcode

Filed under C#

Last modified February 8, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 2825 times

When working on a Winforms or Console application using C# , sometimes you might need to get the computer name where the application is running.

How to get the Computer Name in C# ?

To retrieve the computer name , one can use the System.Environment.MachineName property as shown below.

using System;
namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            var computerName = System.Environment.MachineName;
            Console.WriteLine(computerName);
            Console.ReadLine();
        }
    } 
}
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

Creating Button in XAML in WPF and Windows Store App

Below is a sample Xaml code that is used to create a button in WPF and Windows Store App. <Butto...

How to Pass enum as command parameter in Xaml ?

Below is a sample code snippet demonstrating how to pass enum as command parameter in Xaml. How to ...

How to stretch ListBox Items horizontally to full width of the ListBox in Xaml ?

If you want the list items to horizontally stretch to full width of the ListBox in Xaml , you can se...