Phương thức Uri.MakeRelativeUri (Uri) trong C # được sử dụng để xác định sự khác biệt giữa hai trường hợp Uri.
Cú pháp
Sau đây là cú pháp -
public Uri MakeRelativeUri (Uri uri);
Ở trên, URI là URI để so sánh với URI 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.MakeRelativeUri (Uri) -
using System;
public class Demo {
public static void Main(){
Uri newURI1 = new Uri("https://www.tutorialspoint.com/");
Console.WriteLine("URI = "+newURI1);
Uri newURI2 = new Uri("https://www.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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
URI = https://www.tutorialspoint.com/ URI = https://www.tutorialspoint.com/java.htm Both the URIs aren't equal! Relative uri = java.htm
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.MakeRelativeUri (Uri) -
using System;
public class Demo {
public static void Main(){
Uri newURI1 = new Uri("https://www.tutorialspoint.com/");
Console.WriteLine("URI = "+newURI1);
Uri newURI2 = new Uri("https://www.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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
URI = https://www.tutorialspoint.com/ URI = https://www.tutorialspoint.com/jquery.htm#abcd Both the URIs aren't equal! Relative uri = jquery.htm#abcd