本文介绍了有没有在PowerShell中的函数指针或函数数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿做这样的事情。索引函数数组,并应用适当功能所需的环路索引

 为($ I = 0; $ I -lt 9; $ I ++)
{
    $域[$ i] = $域[$ i] | $($ FunctionTable [$ i])
}
#F1..F9定义函数或过滤,而功能$ FunctionTable = {F1},
                {F2},
                {F3},
                {F4},
                {F5},
                {} F6,
                {} F7,
                {} F8,
                {} F9


解决方案

下面是如何做到这一点使用电话(安培)为例运营商

 #定义3种功能
起作用的{一个}
函数b {B}
函数c {C}#创建3阵列functioninfo对象
$名单= @(
  (胃肠道功能:一)
  (胃肠道功能:B),
  (胃肠道功能:C)
)0,1,2 | {的foreach
  在索引0,1,2#通话功能
  &安培; $列表[$ _]
}

-Oisin

P.S。这意味着你应该管道BVE修订,是​​这样的:

  $域[$ i] = $域[$ i] | &安培; $ FunctionTable [$ i]

I would like to do something like this. Index into an array of functions and apply the appropriate function for the desired loop index.

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}
解决方案

Here's an example of how to do this using the call (&) operator.

# 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[$_]
}

-Oisin

p.s. this means your pipeline should bve amended to something like:

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

这篇关于有没有在PowerShell中的函数指针或函数数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:45