Peter,
Yeah, but, they all changed with 2005 to have generics too right?
There is a new namespace, System.Collections.Generic. The Generics flavor
of the collection classes mainly provide a higher degree of type safety.
For example, let's say we want to have a dictionary that uses an integer as
the key and a DateTime as the value. The non-Generic version might be coded
as:
System.Collections.Specialized.HybridDictionary x = new
System.Collections.Specialized.HybridDictionary();
x.Add(1, DateTime.Now);
x.Add("Hello", "World"); // compiles and runs without errors
The non-generic version allows the wrong type of data to be added to the
collection at run-time. Also note that there are no compile-time issues.
The generics version won't allow you to even compile your application:
System.Collections.Generic.Dictionary<int, DateTime> y = new
System.Collections.Generic.Dictionary<int, DateTime>();
y.Add(1, DateTime.Now);
y.Add("Hello", "World"); // compiler error 1) can't convert string to int
and 2) can't convert string to DateTime
So one benefit of Generics is the type safety. However, there are simple
ways to guarantee type safety and use the non-generic incantations of the
collections.
Regards,
Randy