Silverlight and ArrayList

前端 未结 2 1714
夕颜
夕颜 2021-01-12 11:11

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?

相关标签:
2条回答
  • 2021-01-12 11:57

    An alternative is using:

    IList <object> list = new List <object>();
    
    0 讨论(0)
  • 2021-01-12 11:59

    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.

    0 讨论(0)
提交回复
热议问题