System.Collections classes are obsolete

Collection classes like ArrayList, SortedList, Stack and Hashtable will shortly be obsoleted (i.e. the ObsoleteAttribute will be applied to them in upcoming .NET Framework builds).  You can start to see this in the Silverlight Alpha (i.e. the Obsolete attribute), but they will be physically unavailable in the release version.

More details can be found in a recent Base Class Library Team blog entry Non-Generic Collections to be Removed from Silverlight.

Even if you don't plan on writing Silverlight-compatible code you should avoid using the types detailed in the BCL Teams blog because they'll be obsolete in other future versions of the .NET Framework.

Published Tue, Jun 26 2007 11:36 by PeterRitchie

Comments

# re: System.Collections classes are obsolete

Hmm. Nice that Specialized.StringCollection is not going to be removed (well it seems like it). I quite like how easy it is when using it in My.Settings.

Friday, June 29, 2007 7:07 AM by Andrew Vos

# re: System.Collections classes are obsolete

The Specialized namespace isn't included at all with Silverlight.  It's were inferring some sort of direction based on Silverlight, it doesn't look good.

Friday, June 29, 2007 10:06 AM by PeterRitchie

# re: System.Collections classes are obsolete

According to the comments section of the cited BCL blog entry, there are no plans to remove non-generic collections from the .NET framework.  This removal only applies to Silverlight.

And it's a good thing too, since there are situations that require non-generic collections.

For example, the SoapFormatter class doesn't support serializing generic collections.  Currently, an easy way to persist data to a file (for example), is to add the data to a non-generic dictionary (like ListDictionary, Hashtable, etc), and simply serialize it to a file via SoapFormatter.  This results in an easy to read XML file containing the data (and the file is Soap conformant).  To deserialize the data from the file, use SoapFormatter to deserialize it into a non-generic dictionary, then retrieve the data from the dictionary.  This couldn't be done with a generic dictionary because A) they can only take values of a specific type, and B) SoapFormatter doesn't support serializing generic collections.  Using Dictionary<Object> as a generic dictionary would get around (A) but not (B).  (Note that the XmlSerializer doesn't support serializing IDictionary collections, so you couldn't use that either.)

That's just one example of many times were non-generic collections are needed.  But they should be removed for Silverlight to keep Silverlight as small as possible.

Thursday, August 02, 2007 12:00 PM by Pepe

# devvvy

It's really a headache trying to migrate to Silverlight!

class Person

{

protected Hashtable _lstProperties;

public Hashtable Properties <<-- Property type cannot be known apriori! It's template class!

{

get { return _lstProperties; }

set { _lstProperties = value; }

}

}

And property really is a template class ...

class Property<T>

{

...

}

And Silverlight stipulates that every collection be System.Collections.Generic - this means even if I hand out the source code, it can't be consumed from Silverlight.

Monday, February 16, 2009 7:31 PM by devvvy

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: