We can check if a URI is correctly or wrongly built using the IsWellFormedOriginalString()
method.
uri.IsWellFormedOriginalString()
uri
: The Uri instance we want to check if it is correctly built.
A Boolean is returned. If the URI is well-formed, then a true
is returned. Otherwise, false
is returned.
Let's look at the code below:
using System;class UriExample{//Entry point of Programstatic public void Main(){// Create some Uri objectsUri uri1 = new Uri("https://www.educative.io");Uri uri2 = new Uri("https://google.com");Uri uri3 = new Uri("http://maps.google.com/maps?q={!Account.BillingAddress}");Uri uri4 = new Uri("https://www.hello.124/%%");// check if they are correctly builtConsole.WriteLine(uri1.IsWellFormedOriginalString()); // TrueConsole.WriteLine(uri2.IsWellFormedOriginalString()); // TrueConsole.WriteLine(uri3.IsWellFormedOriginalString()); // FalseConsole.WriteLine(uri4.IsWellFormedOriginalString()); // False}}
Uri
instances.Uri
instances were built correctly using the IsWellFormedOriginalString()
method, and then print the results.