【问题标题】:PowerShell: Accessing Key name without ForEach and GetEnumeratorPowerShell:在没有 ForEach 和 GetEnumerator 的情况下访问密钥名称
【发布时间】:2018-03-21 17:09:55
【问题描述】:

我有一个 OrderedDictionaryKeyCollection 包含以下值:

[0] = "Alpha"
[1] = "Bravo"
[2] = "Charlie"
[3] = "Delta"
[4] = "Echo"

如何在不使用 ForEachGetEnumerator 的情况下直接访问 Key[2] 值(“Charlie”)?

【问题讨论】:

  • @($foo)[2] 也许?

标签: powershell hashtable


【解决方案1】:

你可以使用Select-Object -Index:

$OrderedDictionary = [ordered]@{
  Alpha   = ""
  Bravo   = ""
  Charlie = ""
  Delta   = ""
  Echo    = ""
}
$SecondKey = $OrderedDictionary.Keys |Select -Index 2

【讨论】:

    猜你喜欢
    • 2019-02-20
    • 2012-03-05
    • 2017-05-05
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    相关资源
    最近更新 更多