Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
communitycreator

What is the Uri.GetLeftPart() method in C#?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

In C#, the Uri.GetLeftPart() the method is used to get a specified part of a given URI base on its enum.

Syntax

Uri.GetLeftPart()
Syntax for Uri.GetLeftPart() method in C#

Parameter

Uri : This is the URI object we want to get some of its specified parts.

Return value

The value returned is a string value that represents part of the URI.

Example

using System;
class HelloWorld
{
static void Main()
{
// create some URI object
Uri uri1 = new Uri("https://www.educative.io/");
Uri uri2 = new Uri("https://www.educative.io/edpresso");
// get the Authority
string str1 = uri1.GetLeftPart(UriPartial.Authority);
// get the Path
string str2 = uri2.GetLeftPart(UriPartial.Path);
// print the gotten parts
Console.WriteLine(str1);
Console.WriteLine(str2);
}
}
Getting some parts of Enums of the URI

Explanation

  • Lines 7 and 8: We create some URI objects.
  • Lines 11 and 14: We get some parts of the enums of the URI objects that we created.
  • Lines 17–18: We print the parts that we got to the console.

RELATED TAGS

c#
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring