Uri.IsLoopback Property in C# with Example

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#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");  
    }  
}

chevron_right


Output:

Given Uri is not reference of localhost

Example 2:

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");  
    }  
}

chevron_right


Output:

Given Uri is a reference of localhost



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.