Skip to content

Commit d9b88a8

Browse files
committed
Updated rule help
1 parent 77384e1 commit d9b88a8

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

docs/Rules/AvoidUsingArrayList.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Avoid using ArrayList
3-
ms.date: 08/31/2025
3+
ms.date: 04/16/2025
44
ms.topic: reference
55
title: AvoidUsingArrayList
66
---
@@ -10,19 +10,24 @@ title: AvoidUsingArrayList
1010

1111
## Description
1212

13-
Important
13+
Per dotnet best practices, the
14+
[`ArrayList` class](https://learn.microsoft.com/dotnet/api/system.collections.arraylist)
15+
is not recommended for new development, the same recommendation applies to PowerShell:
1416

1517
Avoid the ArrayList class for new development.
1618
The `ArrayList` class is a non-generic collection that can hold objects of any type. This is inline with the fact
1719
that PowerShell is a weakly typed language. However, the `ArrayList` class does not provide any explicit type
1820
safety and performance benefits of generic collections. Instead of using an `ArrayList`, consider using either a
1921
[`System.Collections.Generic.List[Object]`](https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)
20-
class or a fixed PowerShell array. Besides, the `ArrayList.Add` method returns the index of the added element which
21-
often unintendedly pollutes the PowerShell pipeline and therefore might cause unexpected issues.
22-
22+
class or a fixed PowerShell array.
23+
Besides, the `ArrayList.Add` method returns the index of the added element which often unintendedly pollutes the
24+
PowerShell pipeline and therefore might cause unexpected issues.
2325

2426
## How to Fix
2527

28+
In cases where only the `Add` method is used, you might just replace the `ArrayList` class with a generic
29+
`List[Object]` class but you could also consider using the idiomatic PowerShell pipeline syntax instead.
30+
2631
## Example
2732

2833
### Wrong

0 commit comments

Comments
 (0)