Closed
Description
Issue Details
The example code on how to add a hash table doesn't work correctly.
$hash = $hash.Add("Time", "Now")
To show this in action, we can run the below.
$hash = @{}
$hash.GetType()
$hash = $hash.Add("Time", "Now")
$hash.GetType()
$hash -eq $null
Results of running above
PS C:\> $hash = @{}
PS C:\> $hash.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
PS C:\> $hash = @{}
PS C:\> $hash = $hash.Add("Time", "Now")
# Running gettype again after doing the add reveals that the variable is empty
PS C:\> $hash.GetType()
You cannot call a method on a null-valued expression.
At line:2 char:1
+ $hash.GetType()
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
PS C:\> $hash -eq $null
True
Version(s) of document impacted
- Impacts 6 document
- Impacts 5.1 document
- Impacts 5.0 document
- Impacts 4.0 document
- Impacts 3.0 document
Reason(s) for not selecting all version of documents
- The documented feature was introduced in selected version of PowerShell
- This issue only shows up in selected version of the document
Metadata
Metadata
Assignees
Labels
No labels