![](/img/trans.png)
[英]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.