C#: Storting Instance of Objects in (Hashtable)
Posted
by DaGambit
on Stack Overflow
See other posts from Stack Overflow
or by DaGambit
Published on 2010-06-02T19:33:51Z
Indexed on
2010/06/02
19:54 UTC
Read the original article
Hit count: 179
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?
© Stack Overflow or respective owner