Operators are the ONLY place where you can define something that the code you write can NOT have variable syntax. You MUST use the syntax pre-defined for the operator you’re overriding. The table in [Operators] lists which operators can be overridden. The key here is the operator keyword. It marks what you’re declaring as an operator. List the parameter in the order they appear delimited by commas. All custom operators must be declared as members of a struct, class, interface, or enum type—even in DASIL! The sample below shows how to declare typical operators. All operators are implicitly static.
public operator - var int left, var int right returns int public operator -- (\prefix\ | \postfix\) var int assign public operator -- var ref int assign, var int delta ' This is overloaded returns int public operator = var ref int assign, var int newValue ' assignment operator returns int public operator = var int left , var int right ' equality returns boolean
Some notes:
?_:
.As listed in the table below, some operators have two “names”. These can be override with either name.
Name 1 | Name 2 |
---|---|
<> | >< |
>= | => |
<= | =< |
If your type implements IComparable, the compiler will generate the ==, <>, <, <=, >=, and > operators for you.
Wiki: Enums
Wiki: Home
Wiki: Operators
Wiki: keywords-class
Wiki: keywords-enum
Wiki: keywords-interface
Wiki: keywords-operator
Wiki: keywords-out
Wiki: keywords-ref
Wiki: operators-addition
Wiki: operators-and
Wiki: operators-band
Wiki: operators-dec
Wiki: operators-div
Wiki: operators-exponential
Wiki: operators-float-division
Wiki: operators-gt-equal
Wiki: operators-gt
Wiki: operators-inc
Wiki: operators-inequality
Wiki: operators-lt-equal
Wiki: operators-lt
Wiki: operators-minus
Wiki: operators-mod
Wiki: operators-multiplication
Wiki: operators-nor
Wiki: operators-not
Wiki: operators-or
Wiki: operators-xnor
Wiki: operators-xor