Uri.GetLeftPart() Method in C# with Examples
Last Updated :
28 May, 2020
Uri.GetLeftPart() Method is an instance method that is used to get a specified part from the given URI based on passed UriPartial enum.
Syntax: string Uri.GetLeftPart (UriPartial Part);
Parameters:
- Part: It represents UriPartial to get specified part from Uri.
Return Value: This method returns string value to represent specified part of Uri.
Exception: There are two type of exception are:
- System.ArgumentException: If the specified part is not valid.
- System.InvalidOperationException: If the current Uri instance is not an absolute instance.
Below programs illustrate the use of Uri.GetLeftPart() Method:
Example 1:
C#
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Uri val;
string str = val.GetLeftPart(UriPartial.Authority);
Console.WriteLine(str);
}
}
|
Output:
https://www.geeksforgeeks.org
Example 2:
C#
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Uri val;
string str1 = val.GetLeftPart(UriPartial.Path);
Console.WriteLine(str1);
string str2 = val.GetLeftPart(UriPartial.Query);
Console.WriteLine(str2);
string str3 = val.GetLeftPart(UriPartial.Scheme);
Console.WriteLine(str3);
}
}
|
Output:
https://www.geeksforgeeks.org/
https://www.geeksforgeeks.org/
https://
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...