gpt4 book ai didi

powershell - 在 Powershell foreach 循环中检索数组索引?

转载 作者:行者123 更新时间:2023-11-30 23:45:36 28 4
gpt4 key购买 nike

我有一个使用 foreach 关键字的循环:

foreach ($ln in Get-Content "c:\ATextFile.txt" )

是否可以在迭代过程中找出 $ln 引用的数组索引?或者我是否需要为每次循环迭代创建和增加一个单独的计数变量?

最佳答案

是的,要么使用 for 循环(类似于 (gc c:\ATextFile.txt).count 将是上限)或外部计数器。

相关答案(对于 C#,但基本上都使用相同的可枚举概念):How do you get the index of the current iteration of a foreach loop?

关于powershell - 在 Powershell foreach 循环中检索数组索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7183078/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com