Get the user name of the person who is currently logged on to the Windows operating system in CSharp

Description

The following code shows how to get the user name of the person who is currently logged on to the Windows operating system.

Example


/*w ww.jav a 2s .  co m*/
using System;

class Sample
{
    public static void Main()
    {
       Console.WriteLine("UserName: {0}", Environment.UserName);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Development »




Console
Encoding
Environment
Random