Upgrade

 /// <summary>
        /// Converts a hashtable to a generic ditionary
        /// </summary>
        /// <typeparam name="TKey">The type of the key in the hashtable</typeparam>
        /// <typeparam name="TValue">The type of the object in the hashtable</typeparam>
        /// <param name="t">The hashtable</param>
        /// <returns></returns>
        public static Dictionary<TKey, TValue> Upgrade<TKey, TValue>(this Hashtable t)
        {
            var dic = new Dictionary<TKey, TValue>();

            foreach (DictionaryEntry entry in t)
            {
                dic.Add((TKey)entry.Key, (TValue)entry.Value);
            }

            return dic;
        }
Example:
 Hashtable t1 = new Hashtable();
 t1.Add("pi", Math.PI);
 t1.Add("e", Math.E);

 var col = t1.Upgrade<string, double>();

Description

Upgrades a hashtable to a generic dictionary

Details

Double click on the code to select all.

 

;