您的位置:首页 > 运维架构 > Shell

Hash table in PowerShell

2016-05-31 16:21 387 查看
hashtable is easy to create, access and manipulate.

we simply use

$hashTable = @{}


to create an empty hash table.

and use

$hashTable.color = "Blue"


to set the key and value pair.

refer to http://ss64.com/ps/syntax-hash-tables.html, it is very flexible to use hash table.

one thing I want to point out is that whenver we want to traverse the hashtable, what can we do ?

just like an Array in PowerShell, using ForEach can do it.

For hashtable, we can use like:

foreach ($dog in $dogs.GetEnumerator())
{
# do what you like
}


  or

$hashtable.GetEnumerator() | ForEach-Object { … }


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: