Home Dashboard Directory Help
Search

null-coalescing operator by LogicalDiagram


Status: 

Active


4
0
Sign in
to vote
Type: Suggestion
ID: 801626
Opened: 9/19/2013 10:18:32 AM
Access Restriction: Public
0
Workaround(s)
view

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
Details
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
Sign in to post a workaround.