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.tw/");
Console.WriteLine("URI = "+newURI1);
Uri newURI2 = new Uri("https://tutorialspoint.tw/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.tw/ URI = https://tutorialspoint.tw/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.tw/");
Console.WriteLine("URI = "+newURI1);
Uri newURI2 = new Uri("https://tutorialspoint.tw/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.tw/ URI = https://tutorialspoint.tw/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