Quiz #9

1. Write a C# program that adds the names of three cities in Iowa and the number of characters in each of these cities into a Hashtable. Then use a foreach statement (that uses the DictionaryEntry type) to print out the contents of the Hashtable. Don't forget to include using System.Collections;

using System;
using System.Collections;

namespace ConsoleApplication1
{
   class Class1
   {
      static void Main(string[] args)
      {
         Hashtable htable = new Hashtable(7);
         string[] townNames = {"Rembrandt", "Truesdale", "Sioux Rapids"};

         for (int i = 0; i < townNames.Length; i++) 
         {
            htable.Add(townNames[i], townNames[i].Length);
         }

         foreach (DictionaryEntry entry in htable) 
         {
            Console.WriteLine("Key: {0}, Value: {1}", entry.Key, entry.Value);
         }
      }
   }
}