Home » C#

C# | Uri.MakeRelativeUri() Method with Example

Uri.MakeRelativeUri() Method: Here, we are going to learn about the MakeRelativeUri() method of Uri class with example in C#.
Submitted by Nidhi, on March 26, 2020

Uri.MakeRelativeUri() Method

Uri.MakeRelativeUri() method is an instance method of Uri class. This method checks the difference between the current of the object and the specified object and returns the object of the Uri class.

Syntax:

    Uri Uri.MakeRelativeUri(Uri uri);

Parameter(s):

  • Uri uri – represents an object to be checked with current object to determine difference.

Return value:

The return type of this method is Uri, if the hostname and scheme of this URI instance and uri are the same, then this method returns a relative Uri that, when appended to the current URI instance, yields uri. If the hostname or scheme is different, then this method returns a Uri that represents the uri parameter.

Exception:

    System.InvalidOperationException;

Example to demonstrate example of Uri.MakeRelativeUri() method

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        // Create some Uri objects
        Uri uri = new Uri("https://www.includehelp.com/");
        
        // Create a new Uri to check above uri are base of this uri or not.
        Uri newUri = new Uri("https://www.includehelp.com/dot-net/c-sharp-programs.aspx");

        string diffUri = uri.MakeRelativeUri(newUri).ToString();
        
        Console.WriteLine("Difference of uri and newUri is: "+diffUri);
        
    }
}

Output

Difference of uri and newUri is: dot-net/c-sharp-programs.aspx

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.uri.makerelativeuri?view=netstandard-2.1






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.