What is Uri.GetType() method in C#?

Overview

Uniform resource identifier (Uri) is a compact representation of a resource available to our application on the internet. It can link us to an image, a webpage, a pdf file, etc.

The GetType() method is an override method that returns the current type of the Uri object. It is helpful when we need to be sure if a Uri object is actually a Uri object.

Syntax

Uri.GetType()
Syntax for Uri.GetType() in C#

Parameters

Uri: This is the Uri object that we want to get the current type of.

Return value

It returns the type of the current object.

Code

using System;
class HelloWorld
{
static void Main()
{
// Create some Uri objects
Uri uri1 = new Uri("https://www.educative.io/");
Uri uri2 = new Uri("https://www.educative.io/");
Uri uri3 = new Uri("https://www.educative.io/index.html");
Uri uri4 = new Uri("https://www.educative.io/edpresso");
// Get current object
Console.WriteLine(uri1.GetType());
Console.WriteLine(uri2.GetType());
Console.WriteLine(uri3.GetType());
Console.WriteLine(uri4.GetType());
}
}

Explanation

In the above code:

  • Lines 7–10: We create Uri objects.
  • Lines 13–16: We got and printed the current type of the Uri objects we created, which of course is Uri.

Free Resources