@@ -10,23 +10,23 @@ title: AvoidUsingArrayList
1010
1111## Description
1212
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:
13+ Per .NET best practices, the [ ` ArrayList ` class] [ 1 ] is not recommended for new development,
14+ the same recommendation applies to PowerShell:
1615
1716Avoid the ArrayList class for new development.
18- The ` ArrayList ` class is a non-generic collection that can hold objects of any type. This is inline with the fact
19- that PowerShell is a weakly typed language. However, the ` ArrayList ` class does not provide any explicit type
20- safety and performance benefits of generic collections. Instead of using an ` ArrayList ` , consider using either a
21- [ ` System.Collections.Generic.List[Object] ` ] ( https://learn.microsoft.com/dotnet/api/system. collections.generic.list-1 )
22- class or a fixed PowerShell array.
23- Besides, the ` ArrayList.Add ` method returns the index of the added element which often unintentionally pollutes the
24- PowerShell pipeline and therefore might cause unexpected issues.
17+ The ` ArrayList ` class is a non-generic collection that can hold objects of any type.
18+ This is in line with the fact that PowerShell is a weakly typed language. However, the
19+ ` ArrayList ` class does not provide any explicit type safety and performance benefits
20+ of generic collections. Instead of using an ` ArrayList ` , consider using either a
21+ [ ` System.Collections.Generic.List[Object] ` ] [ 2 ] class or a fixed PowerShell array.
22+ Besides, the ` ArrayList.Add ` method returns the index of the added element which often
23+ unintentionally pollutes the PowerShell pipeline and therefore might cause unexpected issues.
2524
2625## How to Fix
2726
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.
27+ In cases where only the ` Add ` method is used, you might just replace the ` ArrayList ` class
28+ with a generic ` List[Object] ` class but you could also consider using the idiomatic PowerShell
29+ pipeline syntax instead.
3030
3131## Example
3232
@@ -49,4 +49,13 @@ $List = [System.Collections.Generic.List[Object]]::new()
4949``` powershell
5050# Creating a fixed array by using the PowerShell pipeline
5151$List = 1..3 | ForEach-Object { $_ }
52- ```
52+ ```
53+
54+ ### Parameters
55+
56+ - ` Enable ` : ** bool** (Default value is ` $false ` )
57+
58+ Enable or disable the rule during ScriptAnalyzer invocation.
59+
60+ [ 1 ] : https://learn.microsoft.com/dotnet/api/system.collections.arraylist " ArrayList Class "
61+ [ 2 ] : https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1 " List<T> Class "
0 commit comments