PowerShell: Why does truth contain a lie?

PS C:\> $true -contains "Lies"
True

...?

help about_operators He speaks

Comparison operators

include containment operators (in, -notin, -contains, -notcontains), which determine whether the test value appears in the reference set.

$trueis not a container type, how can it be a "reference set" and contain ... anything at all? It does not contain false things.


Similarly $null -in $null, True

+4
source share
1 answer

$true is converted to a set of 1 element, so it is equivalent to:

# ~> @($true) -contains "Lies"
True

So, each item in the collection is compared to "Lies":

# ~> $true -eq "Lies"
True

, , true. , , , :

# ~> $true -eq [Bool]"Lies"
True

:

# ~> [Bool]"Lies"
True

, :

# ~> "Lies" -eq $true
False

:

# ~> [String]$true
True

, $null -in $null $null -in @($null) $null -eq $null .

+7

All Articles