Is casting for 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 quirks of PowerShell often surprise me. Usually I try to work with similar things from the language specification, but the closest to what seems to be is stackoverflow.

  • Are the two statements above equivalent for all the possible types and values โ€‹โ€‹of $SomeObject ?

  • Is the answer to (1) actually baked in the CLR? If so, how can I say that this is so?

+2
casting powershell if-statement equivalent
May 6 '15 at 10:41 PM
source share

No one has answered this question yet.

See related questions:

3486
Why do Java + =, - =, * =, / = assignment operators do not require casting?
2964
How to cast int to enum?
2296
Print malloc result?
1510
Regular casting vs. static_cast vs. dynamic_cast
748
Putting a simple if-then-else statement on one line
701
Python && equivalent (boolean) in if statement
688
if else in AngularJS templates
645
Direct casting against the "how" operator?
379
Stacking multi-line conditions in if expressions?
335
Safely injecting long into int in Java



All Articles