C# Uri MakeRelativeUri

Description

Uri MakeRelativeUri determines the difference between two Uri instances.

Syntax

Uri.MakeRelativeUri has the following syntax.


public Uri MakeRelativeUri(
  Uri uri
)

Parameters

Uri.MakeRelativeUri has the following parameters.

  • uri - The URI to compare to the current URI.

Returns

Uri.MakeRelativeUri method returns 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.

Example

The following example creates 2 Uri instances. The difference in the path information is written to the console.


/*from   w w  w .j  a  va 2 s  .co m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    // Create a base Uri.
    Uri address1 = new Uri("http://www.java2s.com/");
    
    // Create a new Uri from a string.
    Uri address2 = new Uri("http://www.java2s.com/index.htm?date=today"); 
    
    // Determine the relative Uri.  
    Console.WriteLine("The difference is {0}", address1.MakeRelativeUri(address2));

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version