IPAddress.ToString Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Converts an Internet address to its standard notation.
Assembly: System.Net (in System.Net.dll)
Return Value
Type: System.StringA string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation.
| Exception | Condition |
|---|---|
| SocketException | An error prevented the IPv6 address from being converted to a string. |
The ToString method converts the IP address that is stored in the Address property to either IPv4 dotted-quad or IPv6 colon-hexadecimal notation.
// This method displays the value of the current host loopback address in // standard compressed format. try { // Get the loopback address. IPAddress loopBack = IPAddress.IPv6Loopback; // Transform the loop-back address to a string using the overladed // ToString() method. Note that the resulting string is in the compact // form: "::1". string ipv6LoopBack = loopBack.ToString(); outputBlock.Text += "The IPv6 Loopback address is: "; outputBlock.Text += ipv6LoopBack; outputBlock.Text += "\n"; } catch (Exception e) { outputBlock.Text += "Exception: "; outputBlock.Text += e.ToString(); outputBlock.Text += "\n"; }
Show: