Search code examples
powershell

Overloading Operator % in PowerShell Classes


When creating custom classes in PowerShell 5 or later, one can overload the comparison operators (by deriving your class from [System.IComparable] and creating a method CompareTo()) and the four "arithmetic" operators +, -, *, and / (by creating static methods op_Addition, op_Subtraction, op_Multiply, and op_Division).

What is the static method needed to overload the modulo operator %? Or is this simply not possible?


Solution

  • The static method you should be able to define/overload on a Powershell class is op_Modulus.