> Beside what the rest said, I would advise you to prefer a generic collection > always, as the non-generic once can be slowly phased out as versions pass. > Indeed, the .NET framework for Silverlight doesn't have them available > anymore. Generics are also better type-safe and performance wise, and lead > to much cleaner code in general in my opinion.
For performance, there's one exception: binary serialization of a Dictionary<T, U>. This is tremendously slow compared to a Hashtable. For serialization purposes use something like this: /// <summary> /// Utility class which can be used instead of a normal Dictionary class when the Dictionary class is serialized. This class is faster and /// has much less overhead than the normal dictionary class, as it doesn't use generic types. Has no additional value for CF.NET /// </summary> /// <typeparam name="TKey">Key type</typeparam> /// <typeparam name="TValue">Value type</typeparam> [Serializable] public class FastDictionary<TKey, TValue> : Dictionary<TKey, TValue> { #region Class Member Declarations [NonSerialized] private SerializationInfo _info; #endregion /// <summary> /// CTor /// </summary> /// <param name="capacity"></param> public FastDictionary( int capacity ) : base( capacity ) { } /// <summary> /// CTor /// </summary> public FastDictionary() : base() { } /// <summary> /// CTor /// </summary> /// <param name="d"></param> public FastDictionary(IDictionary<TKey, TValue> d) : base( d ) { } /// <summary> /// Deserialization CTor /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected FastDictionary(SerializationInfo info, StreamingContext context) { _info = info; } /// <summary> /// Implements the <see cref="T:System.Runtime.Serialization.ISerializable"></see> interface and returns the data needed to serialize the <see cref="T:System.Collections.Generic.Dictionary`2"></see> instance. /// </summary> /// <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> object that contains the information required to serialize the <see cref="T:System.Collections.Generic.Dictionary`2"></see> instance.</param> /// <param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext"></see> structure that contains the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.Dictionary`2"></see> instance.</param> /// <exception cref="T:System.ArgumentNullException">info is null.</exception> public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { object[] keys = new object[base.Count]; object[] values = new object[base.Count]; int i = 0; foreach(KeyValuePair<TKey, TValue> pair in this) { keys[i] = pair.Key; values[i] = pair.Value; i++; } info.AddValue("keys", keys); info.AddValue("values", values); } /// <summary> /// Implements the <see cref="T:System.Runtime.Serialization.ISerializable"></see> interface and raises the deserialization event when the deserialization is complete. /// </summary> /// <param name="sender">The source of the deserialization event.</param> /// <exception cref="T:System.Runtime.Serialization.SerializationException">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> object associated with the current <see cref="T:System.Collections.Generic.Dictionary`2"></see> instance is invalid.</exception> public override void OnDeserialization(object sender) { object[] keys = (object[])_info.GetValue("keys", typeof(object[])); object[] values = (object[])_info.GetValue("values", typeof(object[])); for(int i = 0; i < keys.Length; i++) { base.Add((TKey)keys[i], (TValue)values[i]); } } } FB > > Regards, > -- > Martín Salías > www.Salias.com.ar > Agile Alliance Member - Microsoft MVP > > > On 7/3/07, Russell Collins <[EMAIL PROTECTED]> wrote: > > > > I am trying to determine if I should use a generic List<T> or a > > HashTable to hold some data objects. The main thing is that I want to > > know if there is general knowledge that one just performs better than > > the other. Any feedback would be greatly appreciated. > > > > =================================== > > This list is hosted by DevelopMentor(r) http://www.develop.com > > > > View archives and manage your subscription(s) at > > http://discuss.develop.com > > > > =================================== > This list is hosted by DevelopMentor® http://www.develop.com > > View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com