-
Notifications
You must be signed in to change notification settings - Fork 407
Description
Aside from the important remark:
Important
We don't recommend that you use the ArrayList class for new development. Instead, we recommend that you use the generic List class. The ArrayList class is designed to hold heterogeneous collections of objects. However, it does not always offer the best performance. Instead, we recommend the following:
For a heterogeneous collection of objects, use the List<Object> (in C#) or List(Of Object) (in Visual Basic) type.
For a homogeneous collection of objects, use the List<T> class. See Performance Considerations in the List reference topic for a discussion of the relative performance of these classes. See Non-generic collections shouldn't be used on GitHub for general information on the use of generic instead of non-generic collection types.
The ArrayList.Add method returns an index of the added element which often unintendedly pollutes the PowerShell pipeline and causes unexpected issues, see e.g.:
Note that an ArrayList is not typesafe which is consistent with PowerShell as a loosely language.
Alternatives for a ArrayList type are:
[object[]]which is also loosely but not sizable, or[System.Collections.Generic.List[Object]]with is both sizable and loosely.