Open In App

C# | Uri.IsBaseOf(Uri) Method

Improve
Improve
Like Article
Like
Save
Share
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("http://www.contoso.com/index.htm#search");
 
        // Declaring and initializing 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");
    }
}


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: 
 

 



Last Updated : 04 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads