Ternary operator in PowerShell

后端 未结 13 2082
忘掉有多难
忘掉有多难 2020-11-28 03:56

From what I know, PowerShell doesn\'t seem to have a built-in expression for the so-called ternary operator.

For example, in the C language, which supports the terna

13条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 04:34

    As of PowerShell version 7, the ternary operator is built into PowerShell.

    1 -gt 2 ? "Yes" : "No"
    # Returns "No"
    
    1 -gt 2 ? 'Yes' : $null
    # Get a $null response for false-y return value
    

提交回复
热议问题