Casting with -As and Evaluating with $( )

<#

$a = “12” ; $b = “4”
$a.GetType().Name  #String
$b.GetType().Name  #String
#######################################

$c = $a + $b
$c                                  #124 (results are concatenated)
#Without casting, Powershell determines type from content.
$c.GetType().Name   #Int32

$c -as [string]              #124
[string]$c                     #124
$c.GetType().Name    #Still Int32
#######################################

#Instance casting of the content
$c =  $($a -As [int]) / $($b -As [int])
$c
3

$c.GetType().Name  #Still Type Int32
$b.GetType().Name  #Still Type String
$a.GetType().Name  #Still Type String
#######################################

#Re-casting variables contents
$c = [int]$a / [int]$b
$c
3

$c.GetType().Name   #Still Type Int32
$b.GetType().Name   #Still Type String
$a.GetType().Name   #Still Type String
#######################################

#Casting the variable
PS C:\> [int]$c = $a / $b
PS C:\> $c
3

$c.GetType().Name   #Still Type Int32
$b.GetType().Name   #Still Type String
$a.GetType().Name   #Still Type String
#######################################

tags: Casting, Casting on the fly, Copy & Paste, Powershell, $S, type, type conversion

#>