arrays - PowerShell 中有函数指针或函数数组吗?

标签 arrays function powershell pointers

我想做这样的事情。索引到函数数组并为所需的循环索引应用适当的函数。

for ($i = 0; $i -lt 9; $i++)
{
    $Fields[$i] = $Fields[$i] | $($FunctionTable[$i])
}
#F1..F9 are defined functions or rather filter functions

$FunctionTable =  {F1}, 
                {F2}, 
                {F3},
                {F4},
                {F5},
                {F6},
                {F7},
                {F8},
                {F9}

最佳答案

下面是如何使用调用 (&) 运算符执行此操作的示例。

# define 3 functions
function a { "a" }
function b { "b" }
function c { "c" }

# create array of 3 functioninfo objects
$list = @(
  (gi function:a),
  (gi function:b),
  (gi function:c)
)

0, 1, 2 | foreach {
  # call functions at index 0, 1 and 2
  & $list[$_]
}

-奥辛

附:这意味着您的管道应该修改为:

$Fields[$i] = $Fields[$i] | & $FunctionTable[$i]

关于arrays - PowerShell 中有函数指针或函数数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1094650/

相关文章:

javascript - 获取除最后一个元素之外的所有元素 - JS

php - 从 PHP 脚本调用 Powershell 在 Ubuntu 上没有可用的命令

php - 按键显示数组顺序的最佳方式

javascript - 在 ES6 javascript 中更新现有对象数组

c++ - shellsort 算法不起作用

javascript - Function.prototype.__proto__ 是什么意思?

javascript : function to execute at a later point in time once variables updated

php - PHP 中每月的第二个星期六函数

excel - 是否可以从 Powershell 以只读模式启动 excel

powershell - 从 IIS 绑定(bind)中检索主机名值