loops - Powershell多个阵列(菜鸟)

标签 loops powershell

所以说我有2个数组。

$Letters = ("A","B","C")
$Numbers = ("1","2","3")

您将如何构造一个foreach循环,使其有效:
foreach ($letter in $letters) {set-something $number} where I could do a pair of values such that
A设置为1B设置为2C设置为3,依此类推。这甚至叫什么?我以为它被称为嵌套循环,但到处搜索,这似乎并不是所谓的嵌套循环。非常感谢!

最佳答案

如果是Zip op,则可以解决问题:

C:\PS> $Letters | Foreach {$i=0} {@($_,$Numbers[$i++]}
A
1
B
2
C
3

但我认为您可能想要这样:
C:\PS> $Letters | Foreach {$i=0;$ht=@{}} {$ht."$_"=$Numbers[$i++]}
C:\PS> $ht.A
1
C:\PS> $ht.B
2
C:\PS> $ht.C
3

关于loops - Powershell多个阵列(菜鸟),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19963919/

相关文章:

powershell - 将 bool 值转换为字符串

在 Register-ObjectEvent 的操作中执行函数的 Powershell 控制台问题

c# - 在堆栈中查找最长的字符序列

c - 使用 "for"循环计算 C 中递增的数据点

Python 计算器/定义

powershell - 如何按模板和到期日期过滤x509证书,仅保留新鲜证书?

powershell - switch 语句不处理

python - 使用 lxml 将一个 xml 复制到 python 中的另一个

python - 如何使用 groupby 来避免 python 中的循环

visual-studio - 为什么 Visual Studio 中的所有预生成或生成后事件都失败并显示退出代码 1?