C# 中的 Uri.Equals(Object) 方法


C# 中的 Uri.Equals() 方法比較兩個 Uri 例項是否相等。

語法

以下為語法 −

public override bool Equals (object comparand);

上述引數 comparand 是要與當前例項進行比較的 Uri 例項或 URI 識別符號。

示例

我們現在來看個示例來實現 Uri.Equals() 方法 −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://tutorialspoint.tw/index.htm");
      Console.WriteLine("URI = "+newURI1);
      Uri newURI2 = new Uri("https://tutorialspoint.tw/index.htm");
      Console.WriteLine("URI = "+newURI2);
      if(newURI1.Equals(newURI2))
         Console.WriteLine("Both the URIs are equal!");
      else
         Console.WriteLine("Both the URIs aren't equal!");
   }
}

輸出

這會生成以下輸出 −

URI = https://tutorialspoint.tw/index.htm
URI = https://tutorialspoint.tw/index.htm
Both the URIs aren't equal!

示例

我們現在來看另一個示例來實現 Uri.Equals() 方法 −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://tutorialspoint.tw/index.htm");
      Console.WriteLine("URI = "+newURI1);
      Uri newURI2 = new Uri("https://tutorialspoint.tw/");
      Console.WriteLine("URI = "+newURI2);
      if(newURI1.Equals(newURI2))
         Console.WriteLine("Both the URIs are equal!");
      else
         Console.WriteLine("Both the URIs aren't equal!");
   }
}

輸出

這會生成以下輸出 −

URI = https://tutorialspoint.tw/index.htm
URI = https://tutorialspoint.tw/
Both the URIs aren't equal!

更新於: 13-11-2019

73 次瀏覽

開啟你的 職業生涯

完成該課程即可獲得證書

開始學習
廣告
© . All rights reserved.