我的 OrderedDictionaryKeyCollection 包含以下值:
[0] = "Alpha"
[1] = "Bravo"
[2] = "Charlie"
[3] = "Delta"
[4] = "Echo"
如何在不使用 ForEach 和 GetEnumerator 的情况下直接访问键[2] 值(" Charlie")?
答案 0 :(得分:1)
您可以使用Select-Object -Index
:
$OrderedDictionary = [ordered]@{
Alpha = ""
Bravo = ""
Charlie = ""
Delta = ""
Echo = ""
}
$SecondKey = $OrderedDictionary.Keys |Select -Index 2