C# | DateTime.GetHashCode() Method with Example

DateTime.GetHashCode() Method: Here, we are going to learn about the GetHashCode() method of DateTime class with example in C#.
By IncludeHelp Last updated : August 27, 2023

C# DateTime.GetHashCode() Method

DateTime.GetHashCode() method is used get the 32-bit signed integer hash code of DateTime class object.

Syntax

int DateTime.GetHashCode();

Parameter(s)

  • It does not accept any parameter.

Return value

The return type of this method is int, it returns 32-bit integer hash code.

Example to demonstrate example of DateTime.GetHashCode() method

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int res = 0;

            //Create object of datetime class
            DateTime dt1 = new DateTime(2019,1,1,10,10,10);

            //Get hashcode of DateTime object.
            res = dt1.GetHashCode();

            //Print hashcode of DateTime object.
            Console.WriteLine("HashCode of dt1 is: " + res);

            Console.WriteLine();  
        }
    }
}

Output

HasCode of dt1 is: 1193378513

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.