Skip to main content
4 of 5
added 1 characters in body
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 expression and conversions to apply:

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

which can help determining where needless casts are.

Joey
  • 13.2k
  • 2
  • 43
  • 73