Uri.CheckHostName(String)方法用於確定指定的主機名是否為有效的DNS名稱。
用法: public static UriHostNameType CheckHostName (string name);
Here, it takes the host name to validate. This can be an IPv4 or IPv6 address or an Internet host name.
返回值:此方法返回一個UriHostNameType,它指示主機名的類型。如果無法確定主機名的類型,或者主機名為null或zero-length字符串,則此方法返回Unknown。
以下示例程序旨在說明Uri.CheckHostName()方法的使用:
示例1:
// C# program to demonstrate the
// Uri.CheckHostName(string) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing uri
string uri = "www.geeksforgeeks.org";
// using CheckHostName() method
UriHostNameType value = Uri.CheckHostName(uri);
// Displaying the result
Console.WriteLine("Host type is: {0}", value);
}
}
輸出:
Host type is: Dns
示例2:
// C# program to demonstrate the
// Uri.CheckHostName(string) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing uri
string uri = "http:// localhost:3000";
// using CheckHostName() method
UriHostNameType value = Uri.CheckHostName(uri);
// Displaying the result
Console.WriteLine("Host type is: {0}", value);
}
}
輸出:
Host type is: Unknown
參考:
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Uri.CheckHostName(String) Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。