閱讀英文

共用方式為


Uri.IsBaseOf(Uri) 方法

定義

判斷目前 Uri 執行個體是否為指定之 Uri 執行個體的基底。

public bool IsBaseOf (Uri uri);

參數

uri
Uri

要測試的指定 URI。

傳回

Boolean

如果目前 true 執行個體是 Uri 的基底則為 uri,否則為 false

例外狀況

urinull

範例

此範例會 Uri 建立代表基底 Uri 實例的 實例。 然後,它會從字串建立第二 Uri 個實例。 它會呼叫 IsBaseOf 來判斷基底實例是否為第二個實例的基底。 結果會寫入主控台。

// Create a base Uri.
Uri baseUri = new Uri("http://www.contoso.com/");

// Create a new Uri from a string.
Uri uriAddress = new Uri("http://www.contoso.com/index.htm?date=today");

// Determine whether BaseUri is a base of UriAddress.
if (baseUri.IsBaseOf(uriAddress))
    Console.WriteLine("{0} is the base of {1}", baseUri, uriAddress);

備註

IsBaseOf 用來比較目前的 Uri 實例與指定的 Uri ,以判斷此 URI 是否為指定 Uri 之 的基底。 比較兩 Uri 個物件來判斷基底關聯性時,不會評估使用者資訊 (UserInfo) 。 比較兩個 URI (uri1 和 uri2) 時,如果忽略最後一個斜線 (/) 之後的 uri2 中所有專案,則 uri1 是 uri2 的基底,則兩個 URI 相同。 http://host/path/path/file?query下表使用 作為基底 URI,顯示它是否為其他 URI 的基底。

URI http://host/path/path/file?query 是 的基底
http://host/path/path/file/
http://host/path/path/#fragment
http://host/path/path/MoreDir/"
http://host/path/path/OtherFile?Query
http://host/path/path/
http://host/path/path/file
http://host/path/path
http://host/path/path?query
http://host/path/path#Fragment
http://host/path/path2/
://host/path/path2/MoreDir
http://host/path/File

適用於