title: How to create an array of TimeZoneInfo variables
body: <p>As a beginner in C#, I am trying to improve my code by shortening wherever possible.  I have written a Windows Time Zone application that defines and populates a large number of TimeZoneInfo variables. The problem is there are nearly 90 time zones in use and so my current way of doing this seems cumbersome.  Is it possible to loop using arrays to achieve what 180 lines of code does here?  </p>
  
  <p>In addition to brevity, I also want to be able to trap any error caused by a particular time zone not being defined in the user's PC's registry. Having to wrap each TimeZoneInfo.FindSystemTimeZoneById() in try catch blocks seems extremely clumsy and not the right way to do this. My thought was that a looping structure would make it much easier to trap a specific error.</p>
  
  <pre><code>//Declare the TimeZoneInfo variables: 
  TimeZoneInfo tziHawaii;           
  TimeZoneInfo tziAlaska;          
  TimeZoneInfo tziPacific;           
  TimeZoneInfo tziCentral;            
  ....
  
  // Populate each TimeZoneInfo variable with relevant info:
  tziHawaii = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time");          
  tziAlaska = TimeZoneInfo.FindSystemTimeZoneById("Alaskan Standard Time");           
  tziPacific = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");          
  tziCentral = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
  ....
  </code></pre>
  
  <p>I have attempted to create a looped structure to do what 180 lines of code does above but it doesn't work.  I just cannot see how to create an array of named TimeZoneInfo variables as in the above excerpt (tziHawaii, tziAlaska, etc).  </p>
  
  <p>If anyone could point out the error of my ways, I would be very happy.</p>
  
  <pre><code>string[] arrWindowsTimeZones = new string[] { "Hawaiian Standard Time", "Alaskan Standard Time", "Pacific Standard Time", "Central Standard Time" };
  TimeZoneInfo[] arrTimeZoneInfo = new TimeZoneInfo[] { DON'T KNOW WHAT TO PUT HERE} ;
  
  for (int i = 0; i &lt; arrWindowsTimeZones.GetUpperBound(0) + 1; i++)
  
  {
      arrTimeZoneInfo[i] = TimeZoneInfo.FindSystemTimeZoneById(arrWindowsTimeZones[i]);
  }
  </code></pre>