- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DateTimeOffset.GetHashCode() Method in C#
The DateTimeOffset.GetHashCode method in C# is used to return the hash code for the current DateTimeOffset object. This method returns a 32-bit signed integer hash code.
Syntax
Following is the syntax −
public override int GetHashCode ();
Example
Let us now see an example to implement the DateTimeOffset.GetHashCode() method −
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset1 = new DateTimeOffset(2019, 09, 10, 6, 20, 10, new TimeSpan(-5, 0, 0)); DateTimeOffset dateTimeOffset2 = new DateTimeOffset(2019, 11, 12, 8, 20, 10, new TimeSpan(-5, 0, 0)); Console.WriteLine("DateTimeOffset1 = {0}", dateTimeOffset1); int hash1 = dateTimeOffset1.GetHashCode(); Console.WriteLine("DateTimeOffset1 HashCode = {0}", hash1); int hash2 = dateTimeOffset2.GetHashCode(); Console.WriteLine("DateTimeOffset2 HashCode = {0}", hash2); Console.WriteLine("DateTimeOffset2 = {0}", dateTimeOffset2); int res = DateTimeOffset.Compare(dateTimeOffset1, dateTimeOffset2); // returns <0 since DateTimeOffset1 is earlier than DateTimeOffset2 Console.WriteLine(res); } }
Output
This will produce the following output −
DateTimeOffset1 = 9/10/2019 6:20:10 AM -05:00 DateTimeOffset1 HashCode = -543087392 DateTimeOffset2 HashCode = 64112243 DateTimeOffset2 = 11/12/2019 8:20:10 AM -05:00 -1
Example
Let us now see another example to implement the DateTimeOffset.GetHashCode() method −
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset1 = new DateTimeOffset(2019, 11, 10, 6, 20, 10, new TimeSpan(-5, 0, 0)); Console.WriteLine("DateTimeOffset = {0}", dateTimeOffset1); int hash = dateTimeOffset1.GetHashCode(); Console.WriteLine("DateTimeOffset HashCode = {0}", hash); } }
Output
This will produce the following output −
DateTimeOffset = 11/10/2019 6:20:10 AM -05:00 DateTimeOffset HashCode = -92293937
Advertisements