Skip to content

Commit 8220ff3

Browse files
Apply suggestions from code review
Co-authored-by: Mike F. Robbins <mike.robbins@microsoft.com>
1 parent bb4d4eb commit 8220ff3

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ By default, PowerShell _variables_ aren't _type-constrained_. You can create a
2222
variable containing an instance of one type and later assign values of any
2323
other type. Also, PowerShell automatically converts values to other types, both
2424
explicitly and implicitly. While implicit type conversion can be helpful, there
25-
are pitfalls, especially for users more familiar with languages have stricter
25+
are pitfalls, especially for users more familiar with languages that have stricter
2626
type handling.
2727

2828
## Type-constrained variables and explicit types conversion
@@ -44,8 +44,7 @@ Int32
4444
```
4545

4646
Type casting ensures that only values of the specified type can be assigned to
47-
the variable. If you try to assign a value of a different type that can be
48-
converted to the constrained type, PowerShell performs an implicit conversion.
47+
the variable. PowerShell performs an implicit conversion if you try to assign a value of a different type that can be converted to the constrained type.
4948
For more information, see the [Implicit type conversion][03] section of this
5049
article.
5150

@@ -159,7 +158,7 @@ These examples are equivalent to the enum expression:
159158
A single value (non-array) can be converted to an instance of a type if:
160159

161160
- That type has a (public) single-parameter constructor
162-
- And the value is same type or can be coerced to the type of the parameter
161+
- And the value is the same type or can be coerced to the type of the parameter
163162

164163
For example, the following two lines are equivalent:
165164

@@ -207,7 +206,7 @@ These contexts include:
207206

208207
PowerShell attempts to convert values passed to parameters to match the
209208
parameter type. Type conversion of parameter values occurs in cmdlets,
210-
functions, scripts, scriptblocks, or .NET method where the parameter is
209+
functions, scripts, scriptblocks, or .NET methods where the parameter is
211210
declared with a specific type. Declaring a parameter with the type `[object]`
212211
or not defining a specific type allows any value type to be passed to a
213212
parameter. Parameters can also have custom conversions defined by decorating
@@ -219,7 +218,7 @@ For more information, see [about_Parameter_Binding][08].
219218

220219
For .NET methods, it's better to pass the exact type expected using a type
221220
casts where needed. Without exact types, PowerShell can select the wrong method
222-
overload. And, new method overloads added in future versions of .NET can break
221+
overload. Also, new method overloads added in future versions of .NET can break
223222
existing code. For an extreme example of this problem, see this
224223
[Stack Overflow question][11].
225224

@@ -280,11 +279,11 @@ PS> $guid = New-Object System.Guid($bytes)
280279
New-Object: Cannot find an overload for "Guid" and the argument count: "16".
281280
```
282281

283-
PowerShell treats the `$bytes` array as a list of individual parameters. Even
282+
PowerShell treats the `$bytes` array as a list of individual parameters even
284283
though `$bytes` is an array of bytes and `System.Guid` has a `Guid(Byte[])`
285284
constructor.
286285

287-
This common code pattern is instance of _pseudo method syntax_, which doesn't
286+
This common code pattern is an instance of _pseudo method syntax_, which doesn't
288287
always work as intended. This syntax translates to:
289288

290289
```powershell
@@ -294,7 +293,7 @@ New-Object -TypeName System.Guid -ArgumentList $bytes # !! BROKEN
294293

295294
Given that the type of **ArgumentList** is `[object[]]`, a single argument
296295
that happens to be an array (of any type) binds to it _element by element_. The
297-
workaround is to wrap `$bytes` in an outer array so that PowerShell looks for
296+
workaround is to wrap `$bytes` in an outer array so that PowerShell looks for a
298297
constructor with parameters that match the contents of the outer array.
299298

300299
```powershell
@@ -309,7 +308,7 @@ Guid
309308
The first item of the wrapped array is our original `Byte[]` instance. That
310309
value matches the `Guid(Byte[]]` constructor.
311310

312-
An alternative to array wrapping workaround is to use the intrinsic static
311+
An alternative to the array wrapping workaround is to use the intrinsic static
313312
`new()` method.
314313

315314
```powershell
@@ -377,7 +376,7 @@ PS> $result.GetType().Name
377376
Double
378377
```
379378

380-
If you want to the result to be an **Int64**, you can cast the result type or
379+
If you want the result to be an **Int64**, you can cast the result type or
381380
operands.
382381

383382
```powershell
@@ -390,8 +389,8 @@ Int64
390389
The `L` suffix on the `1` literal forces the result to be an **Int64**. For
391390
more information, see [about_Numeric_Literals][07].
392391

393-
Usually, it's the left-hand side (LHS) operand of PowerShell operators that
394-
determines the data type used in the operation. PowerShell converts (coerces)
392+
Usually, the left-hand side (LHS) operand of PowerShell operators determines
393+
the data type used in the operation. PowerShell converts (coerces)
395394
the right-hand side (RHS) operand to the required type.
396395

397396
```powershell
@@ -456,9 +455,8 @@ custom-defines these operators via [operator overloading][02].
456455
#### Comparison operations
457456

458457
The comparison operators, such as `-eq`, `-lt`, and `-gt`, can compare operands
459-
of different types. For non-strings and non-primitive types, the behavior
460-
depends on whether the LHS type implements interfaces such as `IEquatable` and
461-
`IComparable`.
458+
of different types. The behavior of non-strings and non-primitive types depends on
459+
whether the LHS type implements interfaces such as `IEquatable` and `IComparable`.
462460

463461
The collection-based comparison operators (`-in` and `-contains`) perform per
464462
element `-eq` comparisons until a match is found. It's each individual element

0 commit comments

Comments
 (0)