
14 Expressions
14.2 Operators
14.2.2 Operator overloading
Paragraph 11 All unary and binary operators have predefined implementations that are automatically available in any expression. 2 In addition to the predefined implementations, user-defined implementations can be introduced by including operator declarations in classes and structs (§17.9). 3 User-defined operator implementations always take precedence over predefined operator implementations: Only when no applicable user-defined operator implementations exist will the predefined operator implementations be considered.
Paragraph 21 The overloadable unary operators are: + - ! ~ ++ -- true false[Note: Although true and false are not used explicitly in expressions, they are considered operators because they are invoked in several expression contexts: boolean expressions (§14.16) and expressions involving the conditional (§14.12), and conditional logical operators (§14.11). end note] 2 The overloadable binary operators are:
+ - * / % & | ^ << >> == != > < >= <=Paragraph 31 Only the operators listed above can be overloaded. 2 In particular, it is not possible to overload member access, method invocation, or the =, &&, ||, ?:, checked, unchecked, new, typeof, as, and is operators. Paragraph 41 When a binary operator is overloaded, the corresponding assignment operator, if any, is also implicitly overloaded. 2 For example, an overload of operator * is also an overload of operator *=. 3 This is described further in §14.13. 4 Note that the assignment operator itself (=) cannot be overloaded. 5 An assignment always performs a simple bit-wise copy of a value into a variable. Paragraph 51 Cast operations, such as (T)x, are overloaded by providing user-defined conversions (§13.4). Paragraph 61 Element access, such as a[x], is not considered an overloadable operator. 2 Instead, user-defined indexing is supported through indexers (§17.8). Paragraph 71 In expressions, operators are referenced using operator notation, and in declarations, operators are referenced using functional notation. 2 The following table shows the relationship between operator and functional notations for unary and binary operators. 3 In the first entry, op denotes any overloadable unary prefix operator. 4 In the second entry, op denotes the unary postfix ++ and --operators. 5 In the third entry, op denotes any overloadable binary operator. [Note: For an example of overloading the ++ and --operators see §17.9.1. end note]
| Operator notation | Functional notation |
| op x | operator op(x) |
| x op | operator op(x) |
| x op y | operator op(x,y) |
| |
| Jagger Software Ltd | |
| Company # 4070126 | |
| VAT # 762 5213 42 |