
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Uri.MakeRelativeUri(Uri) Method in C#
The Uri.MakeRelativeUri(Uri) method in C# is used to determine the difference between two Uri instances.
Syntax
Following is the syntax −
public Uri MakeRelativeUri (Uri uri);
Above, the URI is the URI to compare to the current URI.
Example
Let us now see an example to implement the Uri.MakeRelativeUri(Uri) method −
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); } }
Output
This will produce the following output −
URI = https://www.tutorialspoint.com/ URI = https://www.tutorialspoint.com/java.htm Both the URIs aren't equal! Relative uri = java.htm
Example
Let us now see another example to implement the Uri.MakeRelativeUri(Uri) method −
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); } }
Output
This will produce the following output −
URI = https://www.tutorialspoint.com/ URI = https://www.tutorialspoint.com/jquery.htm#abcd Both the URIs aren't equal! Relative uri = jquery.htm#abcd
- Related Articles
- Uri.IsBaseOf(Uri) Method in C#
- How to do Web API versioning with URI in C# ASP.NET WebAPI?
- Difference Between URL and URI
- How to get file URI reference in Java?
- Convert Image to Data URI with JavaScript
- State the differences between URI and URL in Computer Network.
- How to implement my own URI scheme on Android?
- Clone() method in C#
- TrimEnd() method in C#
- Convert.ToDecimal Method in C#
- IsNullOrWhiteSpace() Method in C#
- Convert.ToSingle Method in C#
- Convert.ToChar Method in C#
- Convert.ToDateTime Method in C#
- Convert.ToInt32 Method in C#

Advertisements