Operator ID / comparison without implicit type conversion

When using PowerShell, sometimes we compare objects of different types. The usual scenario $int -eq $bool(i.e., where 0 -eq $false, 0 -ne $trueand any non-zero value are true, but not false).

This is basically a good thing; sometimes it’s a pain (for example, if I look for all the properties of an object that has a value 1, but I do not want all those who have a value $true).

Question

Is there an operator that performs this comparison without conversion; those. which essentially does the same as the javascript identification operator ( ===) ;?

Bonus Question

If there is such an operator, is there a tolerance? that is, although I do not want to treat 1and truehow to identity, it would (sometimes) be helpful if I could be seen [int]1, and [long]1as if they were.

+4
source share
1 answer

PowerShell does not offer such a statement directly, but you can use the standard .NET method [Object]::Equalsto perform such a comparison.

:
Object.Equals, - , - . .NET .

+7

Source: https://habr.com/ru/post/1679441/


All Articles