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

Phương thức Uri.IsBaseOf (Uri) trong C #

Phương thức Uri.IsBaseOf () trong C # được sử dụng để xác định xem cá thể Uri hiện tại có phải là cơ sở của cá thể Uri được chỉ định hay không.

Cú pháp

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

public bool IsBaseOf (Uri uri);

Ở trên, tham số Uri là phiên bản Uri được chỉ định để kiểm tra.

Ví dụ

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

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!");
      if(newURI1.IsBaseOf(newURI2))
         Console.WriteLine("newURI1 is the base address");
      else
         Console.WriteLine("newURI1 isn't the base address");
   }
}

Đầ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!
newURI1 is the base address

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.IsBaseOf () -

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.qries.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!");
      if(newURI1.IsBaseOf(newURI2))
         Console.WriteLine("newURI1 is the base address");
      else
         Console.WriteLine("newURI1 isn't the base address");
   }
}

Đầu ra

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

URI = https://www.tutorialspoint.com/index.htm
URI = https://www.qries.com/
Both the URIs aren't equal!
newURI1 isn't the base address