C# | Uri.ToString() Method
Uri.ToString( ) Method is used to get a canonical string representation for the specified Uri instance.
Syntax: public override string ToString (); Return Value: This method returns a String instance that contains the unescaped canonical representation of the Uri instance. All characters are unescaped except #, ?, and %.
Below programs illustrate the use of Uri.ToString() Method: Example 1:
csharp
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Uri uri = new Uri("HTTP:
string value = uri.ToString();
Console.WriteLine("Converted string is : {0}", value);
}
}
|
Output:
Converted string is: http://www.contoso.com/thick and thin.htm
Example 2:
csharp
using System;
using System.Globalization;
class GFG {
public static void Main()
{
get ( new Uri("http:
get ( new Uri("http:
}
public static void get (Uri uri)
{
string value = uri.ToString();
Console.WriteLine("Converted string is : {0}", value);
}
}
|
Output:
Converted string is: http://www.contoso.com/
Converted string is: http://www.google.com/
Reference:
Last Updated :
17 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...