具有以下功能:PowerShell的函數參數類型
function appendToSB([System.Text.StringBuilder]$sb,
[string]$value){
[void]$sb.append($value)
$sb
}
$sb = new-object -typename system.text.stringbuilder
$sb = appendToSb($sb, "1,")
$sb.tostring() | out-host
我想用使用StringBuilder的我該功能來構建字符串,但我收到以下錯誤:
appendToSB : Cannot process argument transformation on parameter 'sb'. Cannot convert the "System.Object[]" value of ty pe "System.Object[]" to type "System.Text.StringBuilder". At E:\powershell\test.ps1:8 char:11 + appendToSb([system.text.stringbuilder]$sb, "1,") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [appendToSB], ParameterBindingArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,appendToSB
沒有任何人可以解釋函數/函數參數/返回值如何在PowerShell中工作?