Method

# Operator_Negate

<div class="rst-class">

forsearch

</div>

Operator

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to overload the `-</api/language/operators/mathematical/->` operator when used for negation, providing custom functionality.

## Notes

Create an <span class="title-ref">Operator_Negate</span> function in a class to specify the functionality of the `-</api/language/operators/mathematical/->` operator for that class.

In the function, the definition of negation is given for the `Self</api/language/self_keyword>` instance only. No parameters are passed.

## Sample code

In this example, the negation of the Vector class (see `Operator Add</api/language/operators/operator_overloads/operator_add>`), a class with two `Integer</api/data_types/integer>` properties, x and y, is defined as the negative of the square length of the vector.

``` xojo
Function Operator_Negate As Integer
  Var a As Integer
  a = Self.x ^ 2 + Self.y ^ 2
  Return -a
End If
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`-</api/language/operators/mathematical/->` operator.

</div>
