Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving an ArrayList from a Hashtable

Status
Not open for further replies.

sacheson

Programmer
Mar 30, 2000
55
US
OK ... rather trivial question here ...

I have a member level Hashtable. In my test, I've created an ArrayList in the Form_Load event and populated it with three string values. I then add the ArrayList in my Hashtable using the string "First" as the key value.

I have a second event in my class, Button1_Click. In that event, I would like to retrieve the ArrayList from the Hashtable into a new local object ArrayList, then iterate through those values.

I have successfully populated the Hashtable, and gotten as far as determining the value in the hashtable is an ArrayList in the OnClick event. I'm experiencing problems trying to set the new array to the array from the Hashtable.

Clear as mud? Here's my code. I hope this helps.


//member level variable
private Hashtable htTest;

private void Form1_Load(object sender, System.EventArgs e)
{
ArrayList alTest = new ArrayList();
htTest = new Hashtable();

alTest.Add ("One");
alTest.Add ("Two");
alTest.Add ("Three");

htTest.Add ("First", alTest);
}

private void button1_Click(object sender, System.EventArgs e)
{
IDictionaryEnumerator enTest;
ArrayList alNumbers;

if(htTest.Count > 0)
{
enTest = htTest.GetEnumerator();
while(enTest.MoveNext())
{
if(enTest.Value is System.Collections.ArrayList)
//Here's where I'm having problems. There's no ".ToArray"
//method associated with the .Value of the IDictionaryEnumerator
alNumbers = enTest.Value;
{
}
}
 
You can solve it as follows:

alNumbers = (System.Collections.ArrayList) enTest.Value;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top