Open In App

C# | Uri.GetHashCode() Method

Last Updated : 01 May, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
Uri.GetHashCode() Method is used to get the hash code for the URI.
Syntax: public override int GetHashCode (); Return Value: This method returns an Int32 containing the hash value generated for this URI.
Below programs illustrate the use of Uri.GetHashCode() Method: Example 1: csharp
// C# program to demonstrate the
// Uri.GetHashCode() Method
using System;
using System.Globalization;

class GFG {

    // Main Method
    public static void Main()
    {
        // Declaring and initializing address1
        string address1 = "http://www.contoso.com/index.htm#search";

        // Getting HashCode by
        // using GetHashCode() method
        int value = address1.GetHashCode();

        // Displaying the result
        Console.WriteLine("HashCode is : {0}", value);
    }
}
Output:
HashCode is : 2065713268
Example 2: csharp
// C# program to demonstrate the
// Uri.GetHashCode() Method
using System;
using System.Globalization;

class GFG {

    // Main Method
    public static void Main()
    {

        // calling get() method
        get(new Uri("http://www.contoso.com"));
        get(new Uri("http://www.google.com"));
    }

    // defining get() method
    public static void get(Uri address1)
    {

        // Getting HashCode by
        // using GetHashCode() method
        int value = address1.GetHashCode();

        // Displaying the result
        Console.WriteLine("HashCode is : {0}", value);
    }
}
Output:
HashCode is : 2014
HashCode is : 1498
Reference:

Next Article

Similar Reads