Skip to content

Rule request: AvoidArrayList #2147

@iRon7

Description

@iRon7

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 added element which in most cases unintendedly leaks to the PowerShell pipeline and causes unexpected issues, see e.g.:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions