Computer >> Máy Tính >  >> Lập trình >> C#

Phương thức Uri.Equals (Đối tượng) trong C #

Phương thức Uri.Equals () trong C # so sánh hai trường hợp Uri cho bằng nhau.

Cú pháp

Sau đây là cú pháp -

public override bool Equals (object comparand);

Ở trên, tham số so sánh là phiên bản Uri hoặc một định danh URI để so sánh với phiên bản hiện tại.

Ví dụ

Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức Uri.Equals () -

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://www.tutorialspoint.com/index.htm");
      Console.WriteLine("URI = "+newURI1);
      Uri newURI2 = new Uri("https://www.tutorialspoint.com/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!");
   }
}

Đầu ra

Điều này sẽ tạo ra kết quả sau -

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

Ví dụ

Bây giờ chúng ta hãy xem một ví dụ khác để triển khai phương thức Uri.Equals () -

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

Đầu ra

Điều này sẽ tạo ra kết quả sau -

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