IPAddress.TryParse IPAddress.TryParse IPAddress.TryParse IPAddress.TryParse Method

定义

重载

TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress)

确定字符串是否为有效的 IP 地址。Determines whether a string is a valid IP address.

TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress)

TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress)

确定字符串是否为有效的 IP 地址。Determines whether a string is a valid IP address.

public:
 static bool TryParse(System::String ^ ipString, [Runtime::InteropServices::Out] System::Net::IPAddress ^ % address);
public static bool TryParse (string ipString, out System.Net.IPAddress address);
static member TryParse : string *  -> bool
Public Shared Function TryParse (ipString As String, ByRef address As IPAddress) As Boolean

参数

ipString
String String String String

要验证的字符串。The string to validate.

address
IPAddress IPAddress IPAddress IPAddress

字符串的 IPAddress 版本。The IPAddress version of the string.

返回

如果 ipString 能解析 IP 地址,则为 true;否则为 falsetrue if ipString was able to be parsed as an IP address; otherwise, false.

异常

注解

请注意,此方法接受为有效 ipString 值,该值可以解析为Int64,并将该 Int64 然后视为以网络字节顺序,方式类似于 IP 地址的长值的IPAddressdoes 构造函数。Note that this method accepts as valid an ipString value that can be parsed as an Int64, and then treats that Int64 as the long value of an IP address in network byte order, similar to the way that the IPAddress constructor does. 这意味着此方法返回如果 Int64 解析成功,则为 true,即使它表示不是有效的 IP 地址的地址。This means that this method returns true if the Int64 is parsed successfully, even if it represents an address that's not a valid IP address. 例如,如果 ipString"1",此方法返回 true 即使"1"(或 0.0.0.1) 不是有效的 IP 地址,并且您可能希望此方法返回 false。For example, if ipString is "1", this method returns true even though "1" (or 0.0.0.1) is not a valid IP address and you might expect this method to return false. 修复此 bug 会破坏现有应用程序,因此将不会更改当前行为。Fixing this bug would break existing apps, so the current behavior will not be changed. 你的代码可以通过确保它仅使用此方法来分析采用点分十进制格式的 IP 地址来避免此行为。Your code can avoid this behavior by ensuring that it only uses this method to parse IP addresses in dotted-decimal format.

TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress)

public:
 static bool TryParse(ReadOnlySpan<char> ipString, [Runtime::InteropServices::Out] System::Net::IPAddress ^ % address);
public static bool TryParse (ReadOnlySpan<char> ipString, out System.Net.IPAddress address);
static member TryParse : ReadOnlySpan<char> *  -> bool
Public Shared Function TryParse (ipString As ReadOnlySpan(Of Char), ByRef address As IPAddress) As Boolean

参数

ipString
ReadOnlySpan<Char>

返回

适用于