Uri.HostNameType 属性
定义
获取 URI 中指定的主机名的类型。Gets the type of the host name specified in the URI.
public:
property UriHostNameType HostNameType { UriHostNameType get(); };
public UriHostNameType HostNameType { get; }
member this.HostNameType : UriHostNameType
Public ReadOnly Property HostNameType As UriHostNameType
属性值
UriHostNameType 枚举的一个成员。A member of the UriHostNameType enumeration.
例外
此实例代表一个相对 URI,而此属性仅对绝对 URI 有效。This instance represents a relative URI, and this property is valid only for absolute URIs.
示例
下面的示例创建一个 Uri 实例,并将写入 HostNameType 到控制台。The following example creates a Uri instance and writes the HostNameType to the console.
Uri^ address1 = gcnew Uri( "http://www.contoso.com/index.htm#search" );
Console::WriteLine( "address 1 {0} a valid scheme name",
Uri::CheckSchemeName( address1->Scheme ) ? (String^)" has" : " does not have" );
if ( address1->Scheme == Uri::UriSchemeHttp )
{
Console::WriteLine( "Uri is HTTP type" );
}
Console::WriteLine( address1->HostNameType );
Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
Console.WriteLine("address 1 {0} a valid scheme name",
Uri.CheckSchemeName(address1.Scheme) ? " has" : " does not have");
if (address1.Scheme == Uri.UriSchemeHttp)
Console.WriteLine("Uri is HTTP type");
Console.WriteLine(address1.HostNameType);
Dim address1 As New Uri("http://www.contoso.com/index.htm#search")
Console.WriteLine("address 1 {0} a valid scheme name", IIf(Uri.CheckSchemeName(address1.Scheme), " has", " does not have")) 'TODO: For performance reasons this should be changed to nested IF statements
If address1.Scheme = Uri.UriSchemeHttp Then
Console.WriteLine("Uri is HTTP type")
End If
Console.WriteLine(address1.HostNameType)