Sono un principiante in PowerShell e conosco C# abbastanza bene. Recentemente stavo scrivendo questo script PowerShell e volevo creare un Hashset. Così ho scritto ($ azAz è un array)Chiamata al costruttore con Array Argomento da Powershell
[System.Collections.Generic.HashSet[string]]$allset = New-Object System.Collections.Generic.HashSet[string]($azAZ)
e premuto corsa. Ho ricevuto questo messaggio:
New-Object : Cannot find an overload for "HashSet`1" and the argument count: "52".
At filename.ps1:10 char:55
+ [System.Collections.Generic.HashSet[string]]$allset = New-Object System.Collecti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Poi, Ho cercato su google costruttori in PowerShell con parametri array e ha cambiato il codice per:
[System.Collections.Generic.HashSet[string]]$allset = New-Object System.Collections.Generic.HashSet[string](,$azAZ)
In qualche modo, io ora ottenere questo messaggio:
New-Object : Cannot find an overload for "HashSet`1" and the argument count: "1".
At C:\Users\youngvoid\Desktop\test5.ps1:10 char:55
+ [System.Collections.Generic.HashSet[string]]$allset = New-Object System.Collecti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Non riesci a trovare un overload per HashSet e il conteggio argomento 1? Ma stai scherzando? Grazie.
Perché la virgola in (, $ Azaz) ?? –
non so, l'ho preso da una ricerca su google. Non ho nemmeno letto l'articolo, ma almeno ha ottenuto powershell per trattare $ azAZ come argomento 1. Forse è perché la virgola indica argomenti separati? – irisjay
È perché la virgola è l'operatore di creazione dell'array, quindi rende $ azAZ in un array con un singolo elemento di $ azAZ - Penso che @ ($ azAZ) sia un modo più chiaro per creare un array di uno-array. – Massif