Open In App

Uri.IsLoopback Property in C# with Example

Last Updated : 08 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads