Here is a simple PowerShell 5.0 example that implements the .Net IEqualityComparer interface:
Class A:System.Collections.IEqualityComparer { [bool]Equals($x,$y) { return $x -eq $y } [int]GetHashCode($x) { return $x.GetHashCode() } } [A]$a=[A]::new() $a.Equals(1,1) -- returns True $a.Equals(1,2) -- returns False $a.GetHashCode("OK") -- returns 2041362128
You may even have a class (called A) that inherits from another class (called B) and implements IEqualityComparer:
Class A:B,System.Collections.IEqualityComparer {
source share