.net - Does -eq keyword in power shell test reference equality or use Object.Equals() -


does "-eq" in powershell test reference equality (like "==" in c#) or equivalent of calling object.equals()

the test on equality not simple.

consider 'a' -eq 'a' returns true. means powershell more call equals.

further objects equals called expected.

add-type -typedefinition @"     using system;     public class x {         public string property;         public x(string s) {             property = s;         }         public override bool equals(object o) {             system.console.writeline("equals on {0}", property);             return property == ((x)o).property;         }         public override int gethashcode() { return 20; }     } "@  $o1 = new-object x 'a' $o2 = new-object x 'a'  $o1 -eq $o2 

besides powershell uses conversion quite heavily. if operands not of same type, right operand converted type of left operand. that's why '1' -eq 1 succeeds.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -