當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C# Uri.IsBaseOf(Uri)用法及代碼示例


Uri.IsBaseOf(Uri)方法用於確定當前Uri實例是否為指定Uri實例的基礎。

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

返回值:如果當前Uri實例是uri的基數,則此方法返回true,否則返回false。


異常:如果uri為null,則此方法引發ArgumentNullException。

以下示例程序旨在說明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

參考:



相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Uri.IsBaseOf(Uri) Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。