PowerShell数学问题?

nul*_*kes 3 math powershell

function other3($x, $y)
{
    $tmp = $x + $y
    return $tmp
}

$x = 5
$y = 10

$a = other3($x, $y)
Write-Host $a
Run Code Online (Sandbox Code Playgroud)

当它应该返回15时保持返回5 10,这是什么交易?

cri*_*ito 10

要使用两个参数调用other3,请删除括号"()",例如

$a = other3 $x  $y
Run Code Online (Sandbox Code Playgroud)

你当前调用它的方式实际上传递了一个参数,一个带有两个元素的数组,即5和10.第二个参数是空的(可能默认为null),这意味着加法什么都不做,你只需返回$ x参数.