Open In App

C# | Uri.IsBaseOf(Uri) Method

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:
 

csharp
// 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("https://www.microsoft.com/en-us/#search");

        // Declaring and initializing address2
        Uri address2 = new Uri("https://www.microsoft.com/en-us/);

        // 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");
    }
}

Output: 
address1 instance is a base of the specified address2

 

Example 2: 
 

csharp
// 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");
    }
}

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

 

Reference: 
 


 


Similar Reads