C# Uri ToString

Description

Uri ToString gets a canonical string representation for the specified Uri instance.

Syntax

Uri.ToString has the following syntax.


[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public override string ToString()

Returns

Uri.ToString method returns A String instance that contains the unescaped canonical representation of the Uri instance. All characters are unescaped except #, ?, and %.

Example

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 ToString, which returns the canonical form of the string.


//from   w w w . ja  v a  2 s .  c o  m
using System;
public class MainClass{
  public static void Main(String[] argv){  
    // Create a new Uri from a string address.
    Uri uriAddress = new Uri("HTTP://www.java2s.com:80/thick%20and%20thin.htm");
    
    Console.WriteLine(uriAddress.ToString()); 
    
    Console.WriteLine(uriAddress.OriginalString);

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version