Can someone explain to me why these comparisons work they way the do. I had a bug in one of my scripts that took me a little bit to work through. I was using read-host and typing a nu开发者_如何学Cmber. It was storing it as a string.
Write-Host "(`'2`' -gt 9 ) = " ('2' -gt 9 )
Write-Host "(2 -gt 9 ) = " (2 -gt 9 )
Write-Host "(`'2`' -gt 10 ) = " ('2' -gt 10 )
If you are comparing a string to an Int does it use the Ascii value? If so why does the first one show $false, it should be $true.
Then how is it when you change the int to 10 it becomes $true.
On comparison a right value is converted to the type of a left value. Thus, '2' -gt 9
becomes '2' -gt '9'
, that is False, and '2' -gt 10
becomes '2' -gt '10'
, that is True.
精彩评论