PowerShell哈希表双键错误:"a"和"A"

goo*_*oly 5 powershell hashtable

从另一个应用程序我有我想在我的脚本中使用的键值对.
但是他们有例如键"a"和"A" - 这导致错误双键不被允许.

  $x = @{ "a" = "Entry for a"; "A" = "S.th.else for A" }
Run Code Online (Sandbox Code Playgroud)

我能做什么,因为我需要两者或不需要?

先谢谢,
Gooly

Osc*_*ley 7

默认情况下,PowerShell哈希表不区分大小写.试试这个

$h = new-object System.Collections.Hashtable
$h['a'] = "Entry for a"
$h['A'] = "S.th.else for A"
$h[0] = "Entry for 0"
$h[1] = "Entry for 1"
$h
Run Code Online (Sandbox Code Playgroud)

或者这(取决于你喜欢的语法)

$hash = New-Object system.collections.hashtable
$hash.a = "Entry for a"
$hash.A = "S.th.else for A"
$hash.0 = "Entry for 0"
$hash.1 = "Entry for 1"
$hash.KEY
$hash
Run Code Online (Sandbox Code Playgroud)

  • 但这有效: $hash.Add("0","..."); $hash.Add("a","..."); $hash.Add("A","..."); (2认同)