You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: reference/7.5/Microsoft.PowerShell.Core/About/about_Type_Conversion.md
+14-16Lines changed: 14 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ By default, PowerShell _variables_ aren't _type-constrained_. You can create a
22
22
variable containing an instance of one type and later assign values of any
23
23
other type. Also, PowerShell automatically converts values to other types, both
24
24
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
26
26
type handling.
27
27
28
28
## Type-constrained variables and explicit types conversion
@@ -44,8 +44,7 @@ Int32
44
44
```
45
45
46
46
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.
49
48
For more information, see the [Implicit type conversion][03] section of this
50
49
article.
51
50
@@ -159,7 +158,7 @@ These examples are equivalent to the enum expression:
159
158
A single value (non-array) can be converted to an instance of a type if:
160
159
161
160
- 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
163
162
164
163
For example, the following two lines are equivalent:
165
164
@@ -207,7 +206,7 @@ These contexts include:
207
206
208
207
PowerShell attempts to convert values passed to parameters to match the
209
208
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
211
210
declared with a specific type. Declaring a parameter with the type `[object]`
212
211
or not defining a specific type allows any value type to be passed to a
213
212
parameter. Parameters can also have custom conversions defined by decorating
@@ -219,7 +218,7 @@ For more information, see [about_Parameter_Binding][08].
219
218
220
219
For .NET methods, it's better to pass the exact type expected using a type
221
220
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
223
222
existing code. For an extreme example of this problem, see this
0 commit comments