How to test for $null array in PowerShell

前端 未结 6 985
感情败类
感情败类 2020-12-08 00:24

I\'m using an array variable in PowerShell 2.0. If it does not have a value, it will be $null, which I can test for successfully:

PS C:\\> [array]$foo =          


        
6条回答
  •  悲&欢浪女
    2020-12-08 00:49

    if($foo -eq $null) { "yes" } else { "no" }
    
    help about_comparison_operators 
    

    displays help and includes this text:

    All comparison operators except the containment operators (-contains, -notcontains) and type operators (-is, -isnot) return a Boolean value when the input to the operator (the value on the left side of the operator) is a single value (a scalar). When the input is a collection of values, the containment operators and the type operators return any matching values. If there are no matches in a collection, these operators do not return anything. The containment operators and type operators always return a Boolean value.

提交回复
热议问题