null-coalescing operator - by LogicalDiagram

Status : 

 


4
0
Sign in
to vote
ID 801626 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 9/19/2013 10:18:32 AM
Access Restriction Public

Description

Please add a new operator equivalent to the ?? C# null-coalescing operator.

Ex.

PS C:\> $var = $nullVariable ?? "No Value"
No Value

PS C:\> Get-Process -Name explorer | select Nothing | % {$_.Nothing ?? 5}
5
Sign in to post a comment.
Posted by Derp McDerp on 12/20/2013 at 1:08 PM
### Unary -null:
-null rhs == $null -eq $rhs

### Unary -notnull:
-notnull $rhs == $null -ne $rhs

### Binary -null:
$lhs -null $rhs == if ($null -eq $lhs) { $rhs } else { $lhs }
### the $rhs is lazily evaluated and $lhs is evaluated once