C# - TimeZoneInfo.GetHashCode() Method with Example

In this tutorial, we will learn about the C# TimeZoneInfo.GetHashCode() method with its definition, usage, syntax, and example. By Nidhi Last updated : March 31, 2023

TimeZoneInfo.GetHashCode() Method

The TimeZoneInfo.GetHashCode() is a static method and used to get the hash code value of time zones.

Syntax

int TimeZoneInfo.GetHashCode();

Parameter(s)

  • None

Return Value

This method returns an integer value that represents the hash code of the timezone.

C# Example of TimeZoneInfo.GetHashCode() Method

The source code to get the hash code of the time zone is given below. The given program is compiled and executed successfully.

using System;
using System.Globalization;
using System.Collections.ObjectModel;

class TimeZoneInfoDemo {
  //Entry point of Program
  static public void Main() {
    //Create object of date and time format.
    DateTimeFormatInfo datTimeFormat;

    //Create collection for timezones
    ReadOnlyCollection < TimeZoneInfo > ListOftimeZones;

    datTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat;
    ListOftimeZones = TimeZoneInfo.GetSystemTimeZones();

    Console.WriteLine("HashCodes: ");
    foreach(TimeZoneInfo time_zone in ListOftimeZones) {
      Console.WriteLine("\t" + time_zone.GetHashCode());
    }
  }
}

Output

HashCodes:
        -514555984
        -758128916
        -1369885288
        1929871915
        -20620119
        1966587549
        -1011079097
        -1549238612
        867061357
        -2030645691
        -1472553907
        -774670651
        398800922
        -51503002
        1575136615
        -1920434229
        -1759550415
        781531414
        1688170723
        277435212
        780897488
        672784620
        -1290608544
        1061339055
        1409949984
        849007863
        -1010907336
        -91072651
        1857440091
        1289301972
        524845130
        -985979243
        -884914970
        1243702734
        -2134877238
        417657061
        -1072506847
        1951788994
        587654972
        1596262695
        1796499939
        1141185203
        -152181505
        137358981
        -1896308101
        -1437804775
        203046616
        567328507
        390533655
        2030831431
        -2011598098
        -581402749
        -72981115
        1022731794
        2018412928
        271408839
        457374418
        -1818159890
        1602929463
        858250651
        -74019787
        -1714669205
        153346398
        -270438407
        -2049351688
        296234527
        -1887523373
        199744320
        -851594192
        1782768786
        1141291926
        779965156
        -1853844139
        -981867726
        -963623640
        -1152086148
        2058205788
        1859384373
        -846996468
        -409381159
        -1265531735
        -873538331
        13992051
        1703400787
        556097360
        -1534558847
        -1503639322
        2053458808
        -1078326823
        -1759089867
        1773130869
Press any key to continue . . .

C# TimeZoneInfo Class Programs »





Comments and Discussions!

Load comments ↻





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