PowerShell equality operator not a symmetric relation?

前端 未结 4 410
面向向阳花
面向向阳花 2021-01-17 21:00

Can someone please explain to me why the equality operator in PowerShell is not a symmetric relation??

PS> \"\" -eq 0
False
PS> 0 -eq \"\"
True
         


        
4条回答
  •  再見小時候
    2021-01-17 21:03

    When you do "" -eq 0, it is same as "".equals(0) and it returns false.

    0 -eq "" will try to convert "" to in and [int]"" is 0 and hence you get true.

提交回复
热议问题