C# Exercise: 221 System information

In this exercise, you need to create a program that displays specific system details, including the computer name, domain name, and the username of the currently logged-in user. The program should use the classes provided by C# to retrieve this information from the operating system. You will use classes like Environment and System.Security.Principal.WindowsIdentity to obtain these details, which will help you practice interacting with the operating system and retrieving environment information. This exercise will also help you become familiar with accessing system information in console applications.

 Exercise

System information

 Objetive

Create a program that shows specific system details, including the computer name, domain name, and the username of the user who is currently logged in.

 Example Code

// Import necessary namespaces for working with system information
using System;

class SystemInformation
{
    // Main method where the program execution starts
    static void Main()
    {
        // Display the name of the computer
        Console.WriteLine("Computer Name: " + Environment.MachineName);

        // Display the domain name (or "Workgroup" if not part of a domain)
        Console.WriteLine("Domain Name: " + Environment.UserDomainName);

        // Display the username of the currently logged-in user
        Console.WriteLine("User Name: " + Environment.UserName);
    }
}