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:
// C# program to demonstrate the // Uri.IsWellFormedOriginalString() // Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring and initializing address // Validating if Uri is well formed or not // using IsWellFormedOriginalString() method bool value = address1.IsWellFormedOriginalString(); // Displaying the result if (value) Console.WriteLine("uri is well formed"); else Console.WriteLine("uri is not well formed"); } } |
uri is well formed
Example 2:
// C# program to demonstrate the // Uri.IsWellFormedOriginalString() // Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // calling get() method // if The string is not correctly escaped. // The string is an absolute Uri // that represents an implicit // file Uri. get(new Uri("c:\\directory\filename")); // The string is an absolute URI that // is missing a slash before the path. // The parser for the Uri.Scheme indicates // that the original string was not well-formed. // The string contains unescaped backslashes // even if they are treated as forwarding slashes. get(new Uri("http:\\host/path/file")); // The string represents a hierarchical // absolute Uri and does not contain "://". 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); } } // defining get() method public static void get(Uri address) { // Validating if Uri is well formed or not // using IsWellFormedOriginalString() method bool value = address.IsWellFormedOriginalString(); // Displaying the result if (value) Console.WriteLine("uri is well formed"); else Console.WriteLine("uri is poorly formed"); } } |
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:
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | Uri.MakeRelativeUri(Uri) Method
- Array.GetValue() Method in C# with Examples | Set - 1
- C# | CharEnumerator.MoveNext() Method
- C# | Math.IEEERemainder() Method
- C# | Substring() Method
- C# | IndexOfAny() Method
- C# | CharEnumerator.GetType() Method
- File.GetLastWriteTimeUtc() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- C# | Graphics.DrawLine() Method | Set - 1
- UInt16.GetHashCode Method in C# with Examples
- Stack.Peek Method in C#
- C# | IsNullOrEmpty() Method
- C# | Math.Sign() Method
- Int64.CompareTo Method in C# with Examples
- C# | PadRight() Method
- How to use Array.BinarySearch() Method in C# | Set -1
- C# | EndsWith() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

