simple_hastable.htm
Key Words
 

using System;
using System.Collections;
//csc array_hastable_intoclass.cs
namespace ex_hashstable
{
public class ex_Hashtable {
//Below is all you class member
//This is field, to be specific it is a static field mwmwber

static private string field = "Private ";
//specifying access to fields to use outside this class
//declaring and intializing fields at the same time

public string s1="", s2="", s3="",s4="", s5=" Good job";
// below is class constructor, it checks out the object/instances created
public ex_Hashtable() { Console.WriteLine("contructor evoked");}
// below is a method declared public, expect four references
public string process( string s1, string s2, string s3, string s4)
{
// pointing to the variables
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
this.s4 = s4;
// Creates and initializes a new Hashtable.
Hashtable myHT = new Hashtable();
myHT.Add("a", s1);
myHT.Add("b", s2);
myHT.Add("c", s3);
myHT.Add("d", s4);
// Displays the properties and values of the Hashtable.
Console.WriteLine( "---"+ field + "---" );
Console.WriteLine( " Count: {0}", myHT.Count );
Console.WriteLine( " Keys and Values:" );
read( myHT );
// returns a value to the calling routines
return s5;
}
//the main entry point of this application with main
public static void read( Hashtable ht ) {
IDictionaryEnumerator emdic = ht.GetEnumerator();
Console.WriteLine( "\t-KEY-\t-VALUE-" );
while ( emdic.MoveNext() )
Console.WriteLine("\t{0}:\t{1}", emdic.Key, emdic.Value);
Console.WriteLine();
}
}
class test
{
static void Main()
{
Console.WriteLine();
//instances of ex_Hashtable class
ex_Hashtable eh = new ex_Hashtable();
Console.Write("Enter word 1 :");
eh.s1 =Console.ReadLine();
Console.Write("Enter word 2 :");
eh.s2 =Console.ReadLine();
Console.Write("Enter word 3 :");
eh.s3 =Console.ReadLine();
Console.Write("Enter word 4 :");
eh.s4 =Console.ReadLine();
Console.WriteLine(eh.process(eh.s1,eh.s2,eh.s3,eh.s4));
Console.ReadLine();
}
}
}

//end of the name space