Skip to main content

Casting to string:

[string]$x

vs.

"$x"

Casting to string like this can also be used to flatten an array of strings, instead of joining it:

$a = @('a','b','c')
$a -join ' '

vs.

$a = @('a','b','c')
"$a"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expression and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expression and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

Casting to string:

[string]$x

vs.

"$x"

Casting to string like this can also be used to flatten an array of strings, instead of joining it:

$a = @('a','b','c')
$a -join ' '

vs.

$a = @('a','b','c')
"$a"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expression and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

added 1 characters in body
Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expressenexpression and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expressen and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expression and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

added 1 characters in body
Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the ypetype of the left operand to determine the final type of an expressen and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the ype of the left operand to determine the final type of an expressen and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

Casting to string:

[string]$x

vs.

"$x"

Casting a string to a numeric type:

[int]$x     [float]$x

vs.

+$x

Also very useful to know that PowerShell always takes the type of the left operand to determine the final type of an expressen and conversions to apply:

'1'+2    -> '12'
1+'2'    -> 3

which can help determining where needless casts are.

added 256 characters in body
Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73
Loading
Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73
Loading