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


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

Uri.IsBaseOf() 方法

Uri.IsBaseOf() 方法是一個實例方法,用於檢查一個 Uri 的對象是否是另一個 Uri 類對象的基類。此方法返回一個布爾值,如果當前對象基於指定的對象,則返回 true,否則返回 false。

用法:

    bool Uri.IsBaseOf(Uri uri);

參數:

  • Uri uri– 表示可能是當前對象基礎的對象。

返回值:

這個方法的返回類型是boolean, 如果當前對象是指定對象的基礎,則返回 true,否則返回 false。

示例演示 Uri.IsBaseOf() 方法的示例

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        // Create some Uri objects
        Uri uri1 = new Uri("https://www.includehelp.com/");
        Uri uri2 = new Uri("https://www.duggu.com/");

        // Create a new Uri to check above uri are base of this uri or not.
        Uri newUri = new Uri("https://www.includehelp.com/C#_Article.aspx");

        //here we will check given uri is base of another Uri.
        if (uri1.IsBaseOf(newUri))
            Console.WriteLine("uri1 is baseof newUri");
        else
            Console.WriteLine("uri1 is not baseof newUri");

        if (uri2.IsBaseOf(newUri))
            Console.WriteLine("uri2 is baseof newUri");
        else
            Console.WriteLine("uri2 is not baseof newUri");
    }
}

輸出

uri1 is baseof newUri
uri2 is not baseof newUri


相關用法


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