I have the following code:
# Much more efficient than using an Array and +=
$ArrayList = New-Object System.Collections.ArrayList
[void]$ArrayList.Add([PSCustomObject]@{ Username = 'Scissile'; Path = 'C:\Users\Scissile'; Type = 'User'})
[void]$ArrayList.Add([PSCustomObject]@{ Username = 'Mufti'; Path = 'C:\Users\Mufti'; Type = 'User'})
[void]$ArrayList.Add([PSCustomObject]@{ Username = 'Hijinks'; Path = 'C:\Users\Hijinks'; Type = 'User'})
[void]$ArrayList.Add([PSCustomObject]@{ Username = 'Chad'; Path = 'C:\Administrators\Chad'; Type = 'Admin'})
$ArrayList
# Convert an Array to an ArrayList
$NormalArray = 2,4,6,8,10,12,14
$Transformed = [System.Collections.ArrayList]$NormalArray
$Transformed.getType()
The terminal outputs the following:
D:\Dev\Powershell> d:\Dev\Powershell\Snippets\PSCustomObjects.ps1
Username Path Type
-------- ---- ----
Scissile C:\Users\Scissile User
Mufti C:\Users\Mufti User
Hijinks C:\Users\Hijinks User
Chad C:\Administrators\Chad Admin
I can't figure out why $Transformed.getType() is not returning any output to the console. If I comment out $ArrayList on line 7, I do get the output of $Transformed.getType():
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ArrayList System.Object
Can someone explain this behavior? Why can't I get output from $Transformed.getType()?