Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight and ArrayList

Does Visual Studio 2010's Silverlight support ArrayList? If yes then how to use it, if not then why?

How to use ArrayList in Silverlight?

like image 806
Jeevan Bhatt Avatar asked Nov 15 '10 05:11

Jeevan Bhatt


2 Answers

Silverlight don't support ArrayList now, see http://www.infoq.com/news/2007/07/ArrayList-Gone.

EDIT: Here is the content from this link,

an effort to reduce the size of the Silverlight runtime, most of the non-generic collection types will be removed. These include types once considered essential to .NET programming including ArrayList, Hashtable, and Comparer.

According to Inbar Gazit of Microsoft's Base Class Library team, the non-generic collections are not going to ship with Silverlight 1.1. This means that while you can continue to use them with the main .NET distribution, they cannot be used in any assembly targeting Silverlight. The affected classes are:

* ArrayList
* BitArray
* CaseInsensitiveComparer
* CaseInsensitiveHashCodeProvider
* CollectionBase
* Comparer
* CompatibleComparer
* DictionaryBase
* EmptyReadOnlyDictionaryInternal
* Hashtable
* IHashCodeProvider
* KeyValuePairs
* ListDictionaryInternal
* Queue
* ReadOnlyCollectionBase
* SortedList
* Stack

Just to make it clear, Microsoft is not planning on removing these classes or marking them as obsolete in the main .NET distribution at this time.

In order to support scenarios such as data binding where the type is not necessarily known, the following non-generic interfaces will be kept in Silverlight.

* IEnumerator
* IEnumerable
* ICollection
* IComparer
* IDictionary
* IDictionaryEnumerator
* DictionaryEntry
* IEqualityComparer
* IList

Some generic collections have also been dropped from Silverlight. Inbar explains,

Three other generic types were also removed. Queue, Stack and LinkedList were removed from Silverlight. In this case it wasn't because they were non-generic but because they are not considered to be part of the core set of types that we deemed essential to be provided with Silverlight. Remember that Silverlight is a very small download and should only include the smallest set of APIs that will allow for useful development. It's very simple to implement Queue and Stack using List and LinkedList is just a different implementation of List with different performance characteristics and so it's not an essential part of our core collections group.

Do also check C# - Replacement for.NET ArrayList.ToArray(Type) in Silverlight.

like image 107
Singleton Avatar answered Sep 21 '22 13:09

Singleton


An alternative is using:

IList <object> list = new List <object>();
like image 43
Make It Perfect Avatar answered Sep 23 '22 13:09

Make It Perfect