Skip to content
Related Articles
Open in App
Not now

Related Articles

C# Program to Get the Network Domain Name Associated with Current Using Environment Class

Improve Article
Save Article
  • Last Updated : 01 Nov, 2021
Improve Article
Save Article

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, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. By just using some predefined methods we can get the information of the Operating System using the Environment class. In this article, we will get the network domain name associated with the current user. So we use the UserDomainName property of the Environment class. This property is used to get the network domain name associated with the current user. It will throw PlatformNotSupportedException if the OS does not allow the retrieving of the network domain name or also throw InvalidOperationException if this property does not retrieve the network domain name. 



Return type: The return type of this property is a string. And the returned string represents the network domain name.



// C# program to find the network domain name 
// associated with current user. Using the 
// Environment Class
using System;
class GFG{
static public void Main()
    // Declare a variable
    string resultName;
    // Find the network domain name 
    // Using the UserDomainName property 
    // of Environment class
    resultName = Environment.UserDomainName;
    // Display the result
    Console.WriteLine("Network domain name: " + resultName);


Network domain name: Check
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!