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://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);
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
URI = https://www.tutorialspoint.com/ URI = https://www.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://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);
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
URI = https://www.tutorialspoint.com/ URI = https://www.tutorialspoint.com/jquery.htm#abcd Both the URIs aren't equal! Relative uri = jquery.htm#abcd