Skip to content

Commit 414f478

Browse files
OscarFalck17sdwheeler
authored andcommitted
Update hashtable documentation with cloning note
Added note about cloning hashtables with a single key and provided an example using PowerShell.
1 parent 1ebddea commit 414f478

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ $environments.Keys.Clone() | ForEach-Object {
269269
}
270270
```
271271

272+
Do note, you can not clone a hashtable containing a single key, that will throw an error. In such case where you want to clone the keys its better to cast the key(s) to an array instead and iterate over them.
273+
274+
```powershell
275+
@($environments.Keys) | ForEach-Object {
276+
$environments[$_] = 'SrvDev03'
277+
}
278+
```
279+
272280
## Hashtable as a collection of properties
273281

274282
So far the type of objects we placed in our hashtable were all the same type of object. I used ages

0 commit comments

Comments
 (0)