Hashtable
In this chapter you will learn:
Elements in Hashtable
Hashtable is a data structure we can add key and value pair to it.
The following code uses foreach statement to loop through all keys in a hashtable.
using System;/* j av a2s . c om*/
using System.Collections;
class MainClass
{
public static void Main()
{
Hashtable hash = new Hashtable();
hash.Add("A", "1");
hash.Add("B", "2");
hash.Add("C", "3");
hash.Add("D", "4");
hash.Add("E", "5");
foreach (string firstName in hash.Keys)
{
Console.WriteLine("{0} {1}", firstName, hash[firstName]);
}
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Collections