Rob*_*Rob 9 powershell functional-programming powershell-2.0 first-class-functions
我已经使用ScriptBlocks在PowerShell中成功传递了无参数函数.但是,如果函数有参数,我无法使用它.有没有办法在PowerShell中执行此操作?(最好是v2)
Function Add([int] $x, [int] $y)
{
return $x + $y
}
Function Apply([scriptblock] $s)
{
write-host ($s.Invoke(1,2))
}
Run Code Online (Sandbox Code Playgroud)
然后
Apply { Add }
Run Code Online (Sandbox Code Playgroud)
将0写入控制台.Apply会调用Add
,但不传递任何参数(即使用默认[int]值0和0)
归档时间: |
|
查看次数: |
8835 次 |
最近记录: |