Export (0) Print
Expand All

IPAddress.ToString Method

Converts an Internet address to its standard notation.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

[SecuritySafeCriticalAttribute]
public override string ToString()

Return Value

Type: System.String
A string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation.

ExceptionCondition
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.


   // Gets the IP loopback address and converts it to a string.
   string LoopbackIpAddressString = IPAddress.Loopback.ToString();

   outputBlock.Text += "Loopback IP address: ";
   outputBlock.Text += LoopbackIpAddressString;
   outputBlock.Text += "\n";




// 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";
    }


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft