C# | Uri.IsBaseOf(Uri) Method

Uri.IsBaseOf(Uri) Method is used to determine whether the current Uri instance is a base of the specified Uri instance.

Syntax: public bool IsBaseOf (Uri uri);
Here, it takes the specified Uri instance to test.

Return Value: This method returns true if the current Uri instance is a base of uri otherwise, false.

Exception: This method throws ArgumentNullException if uri is null.

Below programs illustrate the use of Uri.IsBaseOf(Uri) Method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Uri.IsBaseOf(Uri) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing address1
        Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
  
        // Declaring and intializing address2
        Uri address2 = new Uri("http://www.contoso.com/index.htm");
  
        // using IsBaseOf() method
        bool value = address1.IsBaseOf(address2);
  
        // Displaying the result
        if (value)
            Console.WriteLine("address1 instance is a base"+
                              " of the specified address2");
        else
            Console.WriteLine("address1 instance is not a "+
                          "base of the specified address2");
    }
}

chevron_right


Output:

address1 instance is a base of the specified address2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Uri.IsBaseOf(Uri) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // calling get() method
        get(new Uri("http://www.contoso.com"),
           new Uri("http://www.contoso.com"));
  
        get(new Uri("http://www.google.com"), 
         new Uri("http://www.facebook.com"));
    }
  
    // defining get() method
    public static void get(Uri address1,
                           Uri address2)
    {
  
        // using IsBaseOf() method
        bool value = address1.IsBaseOf(address2);
  
        // Displaying the result
        if (value)
            Console.WriteLine("address1 instance is a "+
                      "base of the specified address2");
        else
            Console.WriteLine("address1 instance is "+
              "not a base of the specified address2");
    }
}

chevron_right


Output:

address1 instance is a base of the specified address2
address1 instance is not a base of the specified address2

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.