Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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. 

Syntax:

Environment.UserDomainName

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

Example

C#




// 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);
}
}


Output:

Network domain name: Check

Last Updated : 01 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads