Skip to content

Commit f9bc7a4

Browse files
authored
More updates (#11574)
1 parent b00ec93 commit f9bc7a4

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Type_Conversion.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ A value of _any_ type can be coerced to a **Boolean**.
100100
```
101101

102102
- For other types, null values, empty strings, and empty arrays are converted
103-
to `$false`. Other values, including empty hashtables convert to `$true`.
103+
to `$false`.
104104

105105
```powershell
106106
PS> [boolean]''
@@ -109,7 +109,16 @@ A value of _any_ type can be coerced to a **Boolean**.
109109
False
110110
PS> [boolean]'Hello'
111111
True
112-
PS> [boolean]@(1,'Hello')
112+
```
113+
114+
Other values, including empty hashtables convert to `$true`. Single-element
115+
collections evaluate to the Boolean value of their one and only element.
116+
Collections with more than 1 element are always `$true`.
117+
118+
```powershell
119+
PS> [boolean]@(0)
120+
False
121+
PS> [boolean]@(0,0)
113122
True
114123
PS> [boolean]@{}
115124
True
@@ -300,8 +309,9 @@ This common code pattern is an instance of _pseudo method syntax_, which
300309
doesn't always work as intended. This syntax translates to:
301310

302311
```powershell
303-
[byte[]] $bytes = 1..16
304-
New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
312+
PS> [byte[]] $bytes = 1..16
313+
PS> New-Object -TypeName System.Guid -ArgumentList $bytes
314+
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
305315
```
306316

307317
Given that the type of **ArgumentList** is `[object[]]`, a single argument that
@@ -310,7 +320,8 @@ workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
310320
constructor with parameters that match the contents of the outer array.
311321

312322
```powershell
313-
PS> $guid = New-Object System.Guid(@(, $bytes))
323+
PS> [byte[]] $bytes = 1..16
324+
PS> $guid = New-Object -TypeName System.Guid -ArgumentList (, $bytes)
314325
PS> $guid
315326
316327
Guid

reference/7.4/Microsoft.PowerShell.Core/About/about_Type_Conversion.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ A value of _any_ type can be coerced to a **Boolean**.
100100
```
101101

102102
- For other types, null values, empty strings, and empty arrays are converted
103-
to `$false`. Other values, including empty hashtables convert to `$true`.
103+
to `$false`.
104104

105105
```powershell
106106
PS> [boolean]''
@@ -109,7 +109,16 @@ A value of _any_ type can be coerced to a **Boolean**.
109109
False
110110
PS> [boolean]'Hello'
111111
True
112-
PS> [boolean]@(1,'Hello')
112+
```
113+
114+
Other values, including empty hashtables convert to `$true`. Single-element
115+
collections evaluate to the Boolean value of their one and only element.
116+
Collections with more than 1 element are always `$true`.
117+
118+
```powershell
119+
PS> [boolean]@(0)
120+
False
121+
PS> [boolean]@(0,0)
113122
True
114123
PS> [boolean]@{}
115124
True
@@ -300,8 +309,9 @@ This common code pattern is an instance of _pseudo method syntax_, which
300309
doesn't always work as intended. This syntax translates to:
301310

302311
```powershell
303-
[byte[]] $bytes = 1..16
304-
New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
312+
PS> [byte[]] $bytes = 1..16
313+
PS> New-Object -TypeName System.Guid -ArgumentList $bytes
314+
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
305315
```
306316

307317
Given that the type of **ArgumentList** is `[object[]]`, a single argument that
@@ -310,7 +320,8 @@ workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
310320
constructor with parameters that match the contents of the outer array.
311321

312322
```powershell
313-
PS> $guid = New-Object System.Guid(@(, $bytes))
323+
PS> [byte[]] $bytes = 1..16
324+
PS> $guid = New-Object -TypeName System.Guid -ArgumentList (, $bytes)
314325
PS> $guid
315326
316327
Guid

reference/7.5/Microsoft.PowerShell.Core/About/about_Type_Conversion.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ A value of _any_ type can be coerced to a **Boolean**.
100100
```
101101

102102
- For other types, null values, empty strings, and empty arrays are converted
103-
to `$false`. Other values, including empty hashtables convert to `$true`.
103+
to `$false`.
104104

105105
```powershell
106106
PS> [boolean]''
@@ -109,7 +109,16 @@ A value of _any_ type can be coerced to a **Boolean**.
109109
False
110110
PS> [boolean]'Hello'
111111
True
112-
PS> [boolean]@(1,'Hello')
112+
```
113+
114+
Other values, including empty hashtables convert to `$true`. Single-element
115+
collections evaluate to the Boolean value of their one and only element.
116+
Collections with more than 1 element are always `$true`.
117+
118+
```powershell
119+
PS> [boolean]@(0)
120+
False
121+
PS> [boolean]@(0,0)
113122
True
114123
PS> [boolean]@{}
115124
True
@@ -300,8 +309,9 @@ This common code pattern is an instance of _pseudo method syntax_, which
300309
doesn't always work as intended. This syntax translates to:
301310

302311
```powershell
303-
[byte[]] $bytes = 1..16
304-
New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
312+
PS> [byte[]] $bytes = 1..16
313+
PS> New-Object -TypeName System.Guid -ArgumentList $bytes
314+
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
305315
```
306316

307317
Given that the type of **ArgumentList** is `[object[]]`, a single argument that
@@ -310,7 +320,8 @@ workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
310320
constructor with parameters that match the contents of the outer array.
311321

312322
```powershell
313-
PS> $guid = New-Object System.Guid(@(, $bytes))
323+
PS> [byte[]] $bytes = 1..16
324+
PS> $guid = New-Object -TypeName System.Guid -ArgumentList (, $bytes)
314325
PS> $guid
315326
316327
Guid

0 commit comments

Comments
 (0)