gpt4 book ai didi

powershell - 索引到 PowerShell 值集合

转载 作者:行者123 更新时间:2023-12-02 22:32:34 24 4
gpt4 key购买 nike

鉴于:

$settings = @{"Env1" = "VarValue1"; "Env2" = "VarValue2" }
Write-Output "Count: $($settings.Values.Count)"
Write-Output "Value 0: '$($settings.Values[0])'"
Write-Output "Value 1: '$($settings.Values[1])'"

我得到输出:
Count: 2
Value 0 : 'VarValue2 VarValue1'
Value 1 : ''

为什么第一个元素有两个值而第二个元素没有?如何将值作为我可以索引的集合?

最佳答案

我想到了。解决方案是将 Values ICollection 转换为字符串数组。

和:

$values = $settings.Values -as [string[]]

输出变成最初预期的:
Count: 2
Value 0 : 'VarValue2'
Value 1 : 'VarValue1'

我不禁觉得这应该是默认行为。

关于powershell - 索引到 PowerShell 值集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26283198/

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