C#: Storting Instance of Objects in (Hashtable)
- by DaGambit
Hi I tried filling a Hashtable in the following way:
ResearchCourse resCourse= new ResearchCourse();//Class Instance
resCourse.CID="RC1000";
resCourse.CName="Rocket Science";
TaughtCourse tauCourse= new TaughtCourse();//Class Instance
tauCourse.CID="TC1000";
tauCourse.CName="Marketing";
Hashtable catalog = new Hashtable();
catalog.Add("1", "resCourse.CID");
catalog.Add("2", "tauCourse.CID");
foreach (DictionaryEntry de in catalog)
{
Console.WriteLine("{0}, {1}", de.Key, de.Value);
}
Output Result to Console was:
1, resCourse.CID
2, tauCourse.CID
Expected Result to be:
1, RC1000
2, TC2000
What am I misunderstanding about Hashtables?
What is an easy way for the Hashtable to store the class instance and its values?