// statements_foreach_hashtable.cs // Using the Hashtable collection class
using System; using System.Collections; public class MainClass { public static void Main(string [] args) { // Declare a Hashtable object: Hashtable ziphash = new Hashtable(); // Add entries using the Add() method: ziphash.Add("98008", "Bellevue"); ziphash.Add("98052", "Redmond"); ziphash.Add("98201", "Everett"); ziphash.Add("98101", "Seattle"); ziphash.Add("98371", "Puyallup"); // Display contents: Console.WriteLine("Zip code City"); foreach (string zip in ziphash.Keys) { Console.WriteLine(zip + " " + ziphash[zip]); } } }
Output
Zip code City 98201 Everett 98052 Redmond 98101 Seattle 98008 Bellevue 98371 Puyallup
No comments:
Post a Comment
Comments Welcome