Testing for null in Powershell: Why does testing an empty array behave differently from an empty string?

前端 未结 2 1605
灰色年华
灰色年华 2021-01-19 03:26

Consider this code

\"Type: array\"
$v = @()
\"  -eq `$null: $($v -eq $null)\"
\"  -ne `$null: $($v -ne $null)\"

\"Type: string\"
$v = \'\'
\"  -eq `$null: $         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-19 04:01

    When comparison operators are used against a collection, they do not return a boolean value ($true or $false). They return all the members of the collection that meet the condition.

    See:

    Get-help About_Comparison_Operators

提交回复
热议问题