Skip to content

Suggestion: implement ternary conditionals #3239

@mklement0

Description

@mklement0

C-style ternary conditionals would be a handy addition to the language.

For instance, instead of writing:

if ((get-date).tostring("ss") % 2) { 'odd'  } else  { 'even' }

one could write:

(get-date).tostring("ss") % 2   ?   'odd'   :    'even'

It would also relieve a long-standing disappointment:

At Microsoft, “to ship is to choose”. One of the things we were very disappointed in not being able to ship in V1.0 is a ternary operator.

From a PowerShell Team blog post dated 29 December 2006.


Related: implement null-coalescence and null-soaking and null-conditional assignments

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions