Skip to content
Related Articles

Related Articles

Uri.IsLoopback Property in C# with Example
  • Last Updated : 08 Jun, 2020

Uri.IsLoopback Property is property of Uri class which used to check that the specified Uri references the local host. 

Syntax: 

public bool IsLoopback { get; } 

Return Value: The return type of this property is Boolean, if this Uri references the local host it returns true otherwise it returns false. 

Exception: This property will give InvalidOperationException if this instances represents a relative Uri as this property is only applicable for the absolute URI’s.

Example 1: 
 



C#




// C# program to demonstrate the  
// Uri.IsLoopback property  
using System;  
using System.Globalization;  
      
class GFG {  
      
     // Main Method  
    public static void Main()  
    {  
        // Declaring and initializing value1  
        Uri  v1 = new Uri("https://www.geeksforgeeks.org/");  
      
        // using IsLoopback property  
        bool status = v1.IsLoopback;  
      
        // checking the status  
        if (status)  
            Console.WriteLine("Given Uri is a reference of localhost");  
        else
            Console.WriteLine("Given Uri is not reference of localhost");  
    }  
}

Output:

Given Uri is not reference of localhost

Example 2:

C#




// C# program to demonstrate the  
// Uri.IsLoopback property  
using System;  
using System.Globalization;  
      
class GFG {  
      
     // Main Method  
    public static void Main()  
    {  
        // Declaring and initializing value1  
        Uri  v1 = new Uri("http://localhost");  
      
        // using IsLoopback property  
        bool status = v1.IsLoopback;  
      
        // checking the status  
        if (status)  
            Console.WriteLine("Given Uri is a reference of localhost");  
        else
            Console.WriteLine("Given Uri is not reference of localhost");  
    }  
}

Output:

Given Uri is a reference of localhost

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :