C# 中的 Uri.IsBaseOf(Uri) 方法


C# 中的 Uri.IsBaseOf() 方法用于确定当前 Uri 实例是否为指定 Uri 实例的基础。

语法

以下是语法 −

public bool IsBaseOf (Uri uri);

以上,参数 Uri 是要测试的指定 Uri 实例。

示例

现在让我们看一个实现 Uri.IsBaseOf() 方法的示例 −

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

输出

这将产生以下输出 −

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

示例

现在让我们看另一个实现 Uri.IsBaseOf() 方法的示例 −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://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");
   }
}

输出

这将产生以下输出 −

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

更新于: 13-11-2019

117 次浏览

开启你的 职业生涯

完成课程获得认证

开始吧
广告