What is comparison Operator?
Comparison operators let you specify conditions for comparing values and finding values that match specified patterns. To use a comparison operator, specify the values that you want to compare together with an operator that separates these values.
Type comparison
The type comparison operators (-is and -isnot) are used to determine if an object is a specific type.
Operators | Description |
---|---|
-is | Returns true if both object are the same type |
-isnot | Returns true if the objects are not the same type |
-is Operator
Syntax: <object> -is <type reference>
Example:
PS C:\> $stringMsg1 = "dotnet-helpers" $stringMsg2 = 100 $stringMsg1 -is $stringMsg2.GetType() $stringMsg2 -is [int]
OUTPUT
False True
-isnot Operator
Syntax: <object> -is <type reference>
Example:
PS C:\> $stringMsg1 = "dotnet-helpers" $stringMsg2 = 100 $stringMsg1 -isnot $stringMsg2.GetType() $stringMsg2 -isnot [int]
OUTPUT
True False
Hi David,
The left hand side value always be an object (-is of a type). please find the below syntax.
shouldn’t this return true? But I get false
“dfklj”.gettype() -is “lsdkjf”.gettype()