[英]Type mismatch error passing a string to a function from an array (in VBA)
[英]Passing a string type to a function
我有以下代碼:
cls
$input = 'Hello World'
Write-Host '$input.GetType() = ' + $input.GetType()
function some-string-function($input)
{
Write-Host 'In the function now'
Write-Host '$input.GetType() = ' + $input.GetType()
Write-Host '$input (value) = ' + $input
return $input.length
}
$result = some-string-function $input
"`$result = $result"
我得到以下信息:
$input.GetType() = + System.String
In the function now
$input.GetType() = + System.Collections.ArrayList+ArrayListEnumeratorSimple
$input (value) = + System.Collections.ArrayList+ArrayListEnumeratorSimple
$result =
有人可以指出我實際上如何將字符串傳遞給 PowerShell 中的函數嗎?
為了澄清我的評論$input
是一個保留的自動變量。 如果您在some-string-function
使用另一個命名變量更改它,您將獲得預期的行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.