Tuesday, January 19, 2016

Big hint to both PowerShell riddles

PowerShell riddle 1

If ( $x.$x($x,$x–eq $x ) { <# What is $x? #> }

It is a true equality; no type conversion is performed for the comparison.

PowerShell riddle 2

If ( $y.$y($y,$y.$y($y)) -eq 0 ) { <# What is $y? #> }

Again, it is a true equality; no type conversion is performed for the comparison.

Big hint

In PowerShell, when calling a method or property of an object, the name of the method or property can be represented by any expression that evaluates to be the name of the method or property.

These all result in 3.

@( 1, 2, 3 ).Count
@( 1, 2, 3 ).'Count'
@( 1, 2, 3 ).$( [char]67 + 'ou' + "NT".ToLower() )


Answer to riddle 1, which is a hint to riddle 2.

No comments:

Post a Comment