-
PowerShell v3 – Bringing [ordered] to your hashtables
Posted on September 19th, 2011 1 comment*****Warning. This is from a preview release******
When using a hashtable in PowerShell v2 the insertion order is not preserved. So I might be slightly OCD, but this bugs me:
$HashTableOld = @{a=1; b=2; c=3; d=4} $HashTableOld
If you consider the type of the object you will see that it is of .NET type System.Collections.Hashtable$HashTableOld | Get-Member
In PowerShell v3 it is now possible to create an ordered hashtable using the [ordered] syntax
$HashTableNew = [ordered]@{a=1; b=2; c=3; d=4} $HashTableNewThis will create an object of .NET type System.Collections.Specialized.OrderedDictionary
$HashTableNew | Get-Member
Possibly the most significant takeaway from this change is that it came as a feature suggestion from the community. Using http://connect.microsoft.com/PowerShell anybody can submit bugs / feature requests and gather community support for them via voting them up.If you have a good idea, then suggest it – you never know, it might make it into the product!
This feature suggestion came from Diogenus, more details can be found here.
1 Trackbacks / Pingbacks
-
[...] 12) Упорядочить hashtable с использованием [ordered] – http://www.jonathanmedd.net/2011/09/powershell-v3-bringing-ordered-to-your-hashtables.html [...]
Leave a reply
-













Новинки PowerShell V3 часть 4 « Kazun September 19th, 2011 at 22:38