mercredi 6 mai 2015

Is casting to boolean always the same as this degenerate if statement?

Consider these two statements:

$result = [bool]$SomeObject
$result = if ($SomeObject) { $true } else { $false }

These two statements seem equivalent, but I am often surprised by PowerShell's quirks. Normally I'd try to work this kind of thing out from a language specification, but the closest thing to that seems to be stackoverflow.

  1. Are the above two statements equivalent for all possible types and values of $SomeObject?

  2. Is the answer to (1) actually baked into the CLR? If so, how can I tell that is the case?

Aucun commentaire:

Enregistrer un commentaire