How do I get the current username in .NET using C#?

后端 未结 18 1856
忘了有多久
忘了有多久 2020-11-22 09:59

How do I get the current username in .NET using C#?

18条回答
  •  星月不相逢
    2020-11-22 10:23

    Get the current Windows username:

    using System;
    
    class Sample
    {
        public static void Main()
        {
            Console.WriteLine();
    
            //  <-- Keep this information secure! -->
            Console.WriteLine("UserName: {0}", Environment.UserName);
        }
    }
    

提交回复
热议问题