A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C# program to print the hostname of the computer
Q:

C# program to print the hostname of the computer

0

C# program to print the hostname of the computer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to print the hostname of the computer is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to print the hostname of the computer.

using System;
using System.Net;

class Network
{
    static void Main()
    {
        string hostName = "";
        hostName = Dns.GetHostName();
        Console.WriteLine("Hostname of computer: " + hostName);
    }
}

Output:

Hostname of computer: IncludeHelp-PC
Press any key to continue . . .

Explanation:

Here, we created a class Network that contains the Main() method. The Main() method is the entry point for the program.

In the Main() method, we created a string variable hostname then we get the hostname of the local machine using GetHostName() of Dns class. To use Dns class, we need to import System.Net and then print the hostname of the machine on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now