Uri.ToString Method ()
Gets a canonical string representation for the specified Uri instance.
Assembly: System (in System.dll)
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)] public override string ToString()
The string returned by this method does not contain port information when the port is the default port for the scheme.
The following example creates a new Uri instance from a string. It illustrates the difference between the value returned from OriginalString, which returns the string that was passed to the constructor, and from a call to , which returns the canonical form of the string.
// Create a new Uri from a string address. Uri uriAddress = new Uri("HTTP://www.Contoso.com:80/thick%20and%20thin.htm"); // Write the new Uri to the console and note the difference in the two values. // ToString() gives the canonical version. OriginalString gives the orginal // string that was passed to the constructor. // The following outputs "http://www.contoso.com/thick and thin.htm". Console.WriteLine(uriAddress.ToString()); // The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm". Console.WriteLine(uriAddress.OriginalString);
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1