HostName 类

定义

提供主机名或 IP 地址的数据。

public ref class HostName sealed : IStringable
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.IHostNameFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HostName final : IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.IHostNameFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class HostName final : IStringable
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.IHostNameFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HostName : IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.IHostNameFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class HostName : IStringable
function HostName(hostName)
Public NotInheritable Class HostName
Implements IStringable
继承
Object Platform::Object IInspectable HostName
属性
实现

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
应用功能
internetClient privateNetworkClientServer

注解

HostName 类用于初始化网络应用中使用的主机名并提供数据。 HostName 对象可用于本地主机名或用于建立网络连接的远程主机名。

网络应用的其他相关命名空间中的许多类都使用 HostName 对象。 其中包括:

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");
#include <winrt/Windows.Networking.Sockets.h>
using namespace winrt;

int main()
{
    winrt::init_apartment();

    Windows::Networking::HostName hostName{ L"www.contoso.com" };
    Windows::Networking::Sockets::StreamSocket streamSocket;
    // Try to connect.
    streamSocket.ConnectAsync(hostName, L"http").get();
}
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");

构造函数

HostName(String)

从包含主机名或 IP 地址的字符串创建新的 HostName 对象。

属性

CanonicalName

获取 HostName 对象的规范名称。

DisplayName

获取 HostName 对象的显示名称。

IPInformation

获取分配给 HostName 对象的本地 IP 地址的 IPInformation 对象。

RawName

获取用于构造 HostName 对象的原始字符串。

Type

获取 HostName 对象的 HostNameType

方法

Compare(String, String)

比较两个字符串以确定它们是否表示相同的主机名。

IsEqual(HostName)

确定指定的 HostName 对象是否具有与当前 HostName 对象等效的值。

ToString()

返回一个表示 HostName 对象的字符串。

适用于

另请参阅