We can use the Uri.IsBaseOf()
method of the Uri class to check if a particular Uri is the base of another Uri.
uri1.IsBaseOf(uri2)
uri1
: We want to check if uri1
is the base of uri2
.
uri2
: We want to check if uri1
is its base.
The Uri.IsBaseOf()
method returns a boolean value. It returns true
if uri1
is the base Uri of uri2
. Otherwise, it returns false
.
using System;class HelloWorld{static void Main(){// Create some Uri objectsUri uri1 = new Uri("https://www.educative.io/");Uri uri2 = new Uri("https://www.educative.io/edpresso");Uri uri3 = new Uri("https://www.google.com");Uri uri4 = new Uri("https://facebook.com");Uri uri5 = new Uri("https://facebook.com/help.html");// check for base UrisConsole.WriteLine(uri1.IsBaseOf(uri2));Console.WriteLine(uri4.IsBaseOf(uri5));Console.WriteLine(uri4.IsBaseOf(uri3));Console.WriteLine(uri3.IsBaseOf(uri1));}}
IsBaseOf()
method. Then, we print the results to the console.Note: The
Uri.IsBaseOf()
method throws anArgumentNullException
error when the Uri parameter passed to it is null.
using Systclass HelloWorld{static void Main(){// Create some Uri objectsUri uri1 = new Uri("https://www.educative.io/");Uri uri2 = null;// check for base UrisConsole.WriteLine(uri1.IsBaseOf(uri2));}}
IsBaseOf()
method. Then, we print the result to the console. As can be seen in the code, an ArgumentNullException
error was thrown. This error is caused when a null Uri is passed to the Uri.IsBaseOf()
method.