This sounds silly but I was doing looping through a Hashtable and scratching my head on how to get the KEYS from the table when using foreach. If you ever look at the various ICollection or IDictionary derived classes you’ll find that they all have Keys and Values collections but you can’t do anything useful with them to retrieve the key.

 

After my brain block of a few minutes lifted, I remembered that the raw Enumerators let you get at the data, but this isn’t the first time where this didn’t occur to me right away. I figure if I forget somebody else may hunt for this, and well, I need a mental reminder so I won’t forget in the future <g>

 

Here’s how you can do this:

 

protected override void LoadControlState(object savedState)

{

    Hashtable Properties = (Hashtable)savedState;

 

    IDictionaryEnumerator Enum = Properties.GetEnumerator();

    while (Enum.MoveNext())

    {

        string Key = (string)Enum.Key;

        object Value = Enum.Value;

        … do what you have to

    }

}