Powershell中的哈希表 [英] hash tables in powershell
本文介绍了Powershell中的哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PowerShell开发应用程序.我将变量存储在哈希表中.如何将订单保留在哈希表中?我希望顺序与填充哈希表时的顺序相同.
I'm developing an application in PowerShell. I am storing variables in a hashtable. How can I keep the order in the hashtable? I want the order to be the same as I when I filled the hashtable.
推荐答案
哈希表本质上并不维护值的顺序. 网上已经有一些解决方法.检查这些
Hash tables by nature don't maintain the order of values. There are a few workarounds already out on the net. Check these
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
这篇关于Powershell中的哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文