Calling Constructor with Array Argument from Powershell Calling Constructor with Array Argument from Powershell powershell powershell

Calling Constructor with Array Argument from Powershell


This should work:

[System.Collections.Generic.HashSet[string]]$allset = $azAZ

UPDATE:

To use an array in the constructor the array must be strongly typed. Here is an example:

[string[]]$a = 'one', 'two', 'three'$b = 'one', 'two', 'three'# This works$hashA = New-Object System.Collections.Generic.HashSet[string] (,$a)$hashA# This also works$hashB = New-Object System.Collections.Generic.HashSet[string] (,[string[]]$b)$hashB# This doesn't work$hashB = New-Object System.Collections.Generic.HashSet[string] (,$b)$hashB


try like this:

C:\> $allset = New-Object System.Collections.Generic.HashSet[string]C:\> $allset.add($azAZ)True