Host​Name Host​Name Host​Name Host​Name Class

Definition

Provides data for a hostname or an IP address.

public : sealed class HostName : IStringable, IHostNamepublic sealed class HostName : IStringable, IHostNamePublic NotInheritable Class HostName Implements IStringable, IHostName// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer internetClient

Remarks

The HostName class is used to initialize and provide data for a hostname used in network apps. A HostName object can be used for a local hostname or a remote hostname used to establish a network connection.

The HostName object is used by many classes in other related namespaces for network apps. These include the following:


using Windows.Networking;
using Windows.Networking.Sockets;

var serverHost = new HostName("www.contoso.com");
var clientSocket = new Windows.Networking.Sockets.StreamSocket();

// Try to connect to the remote host
await clientSocket.ConnectAsync(serverHost, "http");
using Windows.Networking;
using Windows.Networking.Sockets;

HostName serverHost = new HostName("www.contoso.com");
StreamSocket clientSocket = new Windows.Networking.Sockets.StreamSocket();

// Try to connect to the remote host
await clientSocket.ConnectAsync(serverHost, "http");

using namespace Windows::Networking;
using namespace Windows::Networking::Sockets;

HostName^ serverHost= ref new HostName("www.contoso.com");
StreamSocket^ clientSocket = ref new StreamSocket();

// Try to connect to the remote host
clientSocket->ConnectAsync(serverHost, "http");

Constructors

HostName(String) HostName(String) HostName(String) HostName(String)

Creates a new HostName object from a string that contains a hostname or an IP address.

public : HostName(PlatForm::String hostName)public HostName(String hostName)Public Sub New(hostName As String)// You can use this method in JavaScript.
Parameters
hostName
PlatForm::String String String String

A string that contains a hostname or an IP address.

Remarks

This constructor creates a new HostName object. The hostName parameter can contain a hostname or an IP address. A HostName object can be used for a local hostname or a remote hostname.

The hostName parameter can contain one of the following:

  • The name of a host that can be resolved by the Domain Name System (DNS) or by another namespace provider.
  • The name of a host that matches a string in the following file on the local computer: %WINDIR%\system32\drivers\etc\hosts
  • A string that contains an IPv4 or an IPv6 network address of the host. An IPv4 address string is in dotted-decimal notation ("192.168.1.111", for example). An IPv6 address is in hexadecimal notation ("21DA:00D3:0010:2F3B:02AA:00FF:FE28:9C5A", for example). If the hostName parameter is the "localhost" string, this represents all loopback addresses on the local computer.

The NetworkInformation.GetHostNames method in the Windows.Networking.Connectivity namespace can be used to retrieve a list of host names or IP addresses associated with the local machine. One of these hostnames or IP addresses can then be used for the hostName parameter.

The constructor will fail if the hostName parameter is null or contains an empty string.

Properties

CanonicalName CanonicalName CanonicalName CanonicalName

Gets the canonical name for the HostName object.

public : PlatForm::String CanonicalName { get; }public string CanonicalName { get; }Public ReadOnly Property CanonicalName As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The canonical name for the HostName object.

DisplayName DisplayName DisplayName DisplayName

Gets the display name for the HostName object.

public : PlatForm::String DisplayName { get; }public string DisplayName { get; }Public ReadOnly Property DisplayName As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The display name for the HostName object.

IPInformation IPInformation IPInformation IPInformation

Gets the IPInformation object for a local IP address assigned to a HostName object.

public : IPInformation IPInformation { get; }public IPInformation IPInformation { get; }Public ReadOnly Property IPInformation As IPInformation// You can use this property in JavaScript.

Remarks

The IPInformation property is only set when the HostName object is a local IPv4 or IPv6 address returned by the GetHostNames method. This property represents the IPInformation object for the local IP address. If the HostName object is not a local IPv4 or IPv6 address, this property will be null.

RawName RawName RawName RawName

Gets the original string used to construct the HostName object.

public : PlatForm::String RawName { get; }public string RawName { get; }Public ReadOnly Property RawName As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The original string used to construct the HostName object.

Type Type Type Type

Gets the HostNameType of the HostName object.

public : HostNameType Type { get; }public HostNameType Type { get; }Public ReadOnly Property Type As HostNameType// You can use this property in JavaScript.

Methods

Compare(String, String) Compare(String, String) Compare(String, String) Compare(String, String)

Compares two strings to determine if they represent the same hostname.

public : static int Compare(PlatForm::String value1, PlatForm::String value2)public static int Compare(String value1, String value2)Public Static Function Compare(value1 As String, value2 As String) As int// You can use this method in JavaScript.
Parameters
value1
PlatForm::String String String String

A hostname or IP address.

value2
PlatForm::String String String String

A hostname or IP address.

Returns
int int int int

The return value indicates the lexicographic relation of value1 to value2. If the two parameters represent the same canonical hostname, then zero is returned. If value1 is less than value2, the return value is less than zero. If value1 is greater than value2, the return vale is greater than zero.

Remarks

The Compare method is used to compare two strings to determine if the strings represent the same hostname. This method compares canonical names created from the value1 and value2 parameters to determine the value to return.

IsEqual(HostName) IsEqual(HostName) IsEqual(HostName) IsEqual(HostName)

Determines whether the specified HostName object has an equivalent value to the current HostName object.

public : PlatForm::Boolean IsEqual(HostName hostName)public bool IsEqual(HostName hostName)Public Function IsEqual(hostName As HostName) As bool// You can use this method in JavaScript.
Parameters
hostName
HostName HostName HostName HostName

A HostName object that is compared with the current HostName.

Returns
PlatForm::Boolean bool bool bool

A Boolean value that indicates whether the specified HostName object is equal to the current HostName object.

Remarks

The Equals method determines whether the HostName object specified by the hostName parameter is the same instance of the current HostName object.

The IsEqual method determines whether the HostName object specified by the hostName parameter has an equivalent value to the current HostName object. Two HostName objects are considered to have the equivalent value if the CanonicalName property has the same value.

ToString() ToString() ToString() ToString()

Returns a string that represents the HostName object.

public : PlatForm::String ToString()public string ToString()Public Function ToString() As string// You can use this method in JavaScript.
Returns
PlatForm::String string string string

A string that represents the HostName object.