Method names for operator methods in C #

Does anyone have an exhaustive list of names that C # / CLR provides to operators? (Maybe I do not have enough sleep, but I can not find it on Google). op_Addition, op_Subtraction. Also, is it likely that they will be different in other cultures?

I am trying to create a class that can add / subtract, etc. two objects, and I completed all the primitives - I just need to make a "rest".

Many thanks.

+2
operators c # operator-overloading
source share
4 answers

Here is the complete list of overloaded statements from MSDN.

--- EDIT ---

In response to your comment, I believe what you want here. Search for table 6-1.

+4
source share

Based on the Expression class:

== op_Equality != op_Inequality > op_GreaterThan < op_LessThan >= op_GreaterThanOrEqual <= op_LessThanOrEqual & op_BitwiseAnd | op_BitwiseOr + op_Addition - op_Subtraction / op_Division % op_Modulus * op_Multiply << op_LeftShift >> op_RightShift ^ op_ExclusiveOr - op_UnaryNegation + op_UnaryPlus ! op_LogicalNot ~ op_OnesComplement op_False op_True ++ op_Increment -- op_Decrement 
+3
source share

The accepted answer is good because it refers to a list of overloaded operators, but it does not strictly answer the question, because it does not provide operator names at compilation.

The answer to the second place includes this, but this is an incomplete list and not very organized. For completeness, I made my own list, including several statements that you might expect to be overloaded, but that is not the case. The list is in order of priority of the operator, from the highest (lowest) priority to the lowest.

 Outside of Order of Operations (used when necessary to coerce types) op_Implicit op_True op_False Unary (only one operator) ++ op_Increment (Includes preincrement and postincrement) -- op_Decrement (Includes predecrement and postdecrement) - op_UnaryNegation + op_UnaryPlus ! op_LogicalNot ~ op_OnesComplement op_Explicit await (Not overloadable) Multiplicative / op_Division % op_Modulus * op_Multiply Additive + op_Addition - op_Subtraction Shift << op_LeftShift >> op_RightShift Relational > op_GreaterThan < op_LessThan >= op_GreaterThanOrEqual <= op_LessThanOrEqual as (Not overloadable) is (Not overloadable) Equality == op_Equality != op_Inequality And & op_BitwiseAnd Exclusive Or ^ op_ExclusiveOr Inclusive Or | op_BitwiseOr Conditional And && (Not overloadable - use "implicit operator bool" or "operator true") Contional Or || (Not overloadable - use "implicit operator bool" or "operator true") Null-Coalescing Operator ?? (Not overloadable) Ternary ?: (Not overloadable - use "implicit operator bool" or "operator true") Assignment = (Not overloadable - for combined operator and assignment (such as +=), just use the operator (+)) 

Note. The C # compiler prefers the implicit operator bool instead of the True and False operators, if both are defined.

As indicated by fooobar.com/questions/465918 / ... the following method names are also emitted / understood by the C # compiler, but

  • I ran tests in Visual Studio 2015 and C # 6.0, trying to get them to work, and
  • The C # 5.0 specification lists the "complete set of unary [and binary] operator function names" (Appendix A, p. 469), and they do not appear anywhere.
 Unary & op_AddressOf * op_PointerDereference Binary . op_MemberSelection -> op_PointerToMemberSelection op_SignedRightShift op_UnsignedRightShift = op_Assign *= op_MultiplicationAssignment /= op_DivisionAssignment %= op_ModulusAssignment -= op_SubtractionAssignment += op_AdditionAssignment <<= op_LeftShiftAssignment >>= op_RightShiftAssignment |= op_ExclusiveOrAssignment &= op_BitwiseAndAssignment |= op_BitwiseOrAssignment op_UnsignedRightShiftAssignment op_SignedRightShiftAssignment , op_Comma 
+2
source share

This website provides a list of names for C # statements that display an operator, Action (name), example and result: C # List of statements

0
source share

All Articles