C# | Uri.IsWellFormedOriginalString() Method
Last Updated :
30 Apr, 2019
Uri.IsWellFormedOriginalString() Method is used to show whether the string used to construct this Uri was well-formed and is not required to be further escaped.
Syntax: public bool IsWellFormedOriginalString ();
Return Value: This method returns true if the string was well-formed otherwise, false.
Below programs illustrate the use of Uri.IsWellFormedOriginalString() Method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
bool value = address1.IsWellFormedOriginalString();
if (value)
Console.WriteLine( "uri is well formed" );
else
Console.WriteLine( "uri is not well formed" );
}
}
|
Output:
uri is well formed
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
try {
get ( new Uri( "c:\\directory\filename" ));
get ( new Uri( "http:\\host/path/file" ));
get ( new Uri( "www.contoso.com/path/file" ));
}
catch (UriFormatException e)
{
Console.Write( "uri is so poorly formed that system thrown " );
Console.Write( "{0}" , e.GetType(), e.Message);
Environment.Exit(1);
}
}
public static void get (Uri address)
{
bool value = address.IsWellFormedOriginalString();
if (value)
Console.WriteLine( "uri is well formed" );
else
Console.WriteLine( "uri is poorly formed" );
}
}
|
Output:
uri is well formed
uri is poorly formed
uri is poorly formed
uri is poorly formed
uri is well formed
uri is so poorly formed that system thrown System.UriFormatException
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...