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


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

Uri.Equals() 方法

Uri.Equals() 方法是一種覆蓋方法,用於檢查指定引用與當前對象的相等性。如果兩者相等則返回真,否則返回假。

用法:

    bool Uri.Equals(Uri obj);

參數:

  • Uri obj– 表示要與當前對象一起檢查的指定對象。

返回值:

這個方法的返回類型是Boolean, 如果指定的對象或引用等於當前對象,則返回布爾值,則返回 true,否則返回 false。

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

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        Uri domainUri1;
        Uri domainUri2;
        Uri domainUri3;

        domainUri1 = new Uri("https://www.includehelp.com/index.html");
        domainUri2 = new Uri("https://www.includehelp.com/index.html");
        domainUri3 = new Uri("https://www.includehelp.com/index_1.html");

        if (domainUri1.Equals(domainUri1) == true)
            Console.WriteLine("Both are equal");
        else
            Console.WriteLine("Both are not equal");

        if (domainUri1.Equals(domainUri2) == true)
            Console.WriteLine("Both are equal");
        else
            Console.WriteLine("Both are not equal");

        if (domainUri1.Equals(domainUri3) == true)
            Console.WriteLine("Both are equal");
        else
            Console.WriteLine("Both are not equal");
    }
}

輸出

Both are equal
Both are equal
Both are not equal


相關用法


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