I'm not quite sure if this exact question is a duplicate, but I couldn't find my specific question on stackoverflow, so I guess it's not.
$true
is a boolean type:
($true).getType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Boolean System.ValueType
'true'
is a string:
('true').gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
why is this condition true?
PS C:WINDOWSsystem32> if ('True' -eq $true) {'yes'} else {'no'}
yes
only because the string is called True just like the boolean true? If I compare it with any other string, there is a different outcome:
PS C:WINDOWSsystem32> 'hello' -eq $true
False
PS C:WINDOWSsystem32> 'true' -eq $true
True
if you do 'true' == true
in C# it prints an cannot convert string to bool
error and both C# and PS are based on .net and have quite the same syntax. why is there a different outcome?
this seems very strange to me.
How is PowerShell evaluating 'true'
to $true
?