📜  C#| Uri.IsBaseOf(Uri)方法

📅  最后修改于: 2021-05-29 23:02:09             🧑  作者: Mango

Uri.IsBaseOf(Uri)方法用于确定当前Uri实例是否为指定Uri实例的基础。

下面的程序说明了Uri.IsBaseOf(Uri)方法的用法:

范例1:

// 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");
    }
}
输出:
address1 instance is a base of the specified address2

范例2:

// 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");
    }
}
输出:
address1 instance is a base of the specified address2
address1 instance is not a base of the specified address2

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.isbaseof?view=netstandard-2.1