powershell中的哈希表

RRR*_*RRR 5 powershell hashtable

我正在使用PowerShell开发一个应用程序.我将变量存储在哈希表中.如何在哈希表中保留订单?我希望订单与我填写哈希表时的顺序相同.

rav*_*nth 8

哈希表本质上不保持值的顺序.网上已经有一些解决方法.检查这些

http://www.tellingmachine.com/post/2009/01/When-PowerShell-hash-table-magic-backfires.aspx

http://huddledmasses.org/powershell-and-hashtable-oddities/

或者尝试

PS C:\WINDOWS\system32> $OrderedList = New-Object System.Collections.Specialized.OrderedDictionary
PS C:\WINDOWS\system32> $OrderedList
PS C:\WINDOWS\system32> $OrderedList.Add("Name","Ravi")
PS C:\WINDOWS\system32> $OrderedList.Add("Age","30")
PS C:\WINDOWS\system32> $OrderedList

Name                           Value
----                           -----
Name                           Ravi
Age                            30
Run Code Online (Sandbox Code Playgroud)