C# 中的 Uri.MakeRelativeUri(Uri) 方法
C# 中的 Uri.MakeRelativeUri(Uri) 方法用于确定两个 Uri 实例之间的差异。
语法
以下是语法 −
public Uri MakeRelativeUri (Uri uri);
上面 URI 是要与当前 URI 比较的 URI。
示例
现在,我们来看一个实现 Uri.MakeRelativeUri(Uri) 方法的示例 −
using System;
public class Demo {
public static void Main(){
Uri newURI1 = new Uri("https://tutorialspoint.com/");
Console.WriteLine("URI = "+newURI1);
Uri newURI2 = new Uri("https://tutorialspoint.com/java.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 res = newURI1.MakeRelativeUri(newURI2);
Console.WriteLine("Relative uri = "+res);
}
}输出
这将产生以下输出 −
URI = https://tutorialspoint.com/ URI = https://tutorialspoint.com/java.htm Both the URIs aren't equal! Relative uri = java.htm
示例
现在,我们来看另一个实现 Uri.MakeRelativeUri(Uri) 方法的示例 −
using System;
public class Demo {
public static void Main(){
Uri newURI1 = new Uri("https://tutorialspoint.com/");
Console.WriteLine("URI = "+newURI1);
Uri newURI2 = new Uri("https://tutorialspoint.com/jquery.htm#abcd");
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 res = newURI1.MakeRelativeUri(newURI2);
Console.WriteLine("Relative uri = "+res);
}
}输出
这将产生以下输出 −
URI = https://tutorialspoint.com/ URI = https://tutorialspoint.com/jquery.htm#abcd Both the URIs aren't equal! Relative uri = jquery.htm#abcd
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP