13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14 Expressionsset of candidate operators for the operation. The predefined implementations of a given operator arespecified in the description of the operator (§14.5 and §14.6).• The overload resolution rules of §14.4.2 are applied to the set of candidate operators to select the bestoperator with respect to the argument list (x), and this operator becomes the result of the overloadresolution process. If overload resolution fails to select a single best operator, a compile-time erroroccurs.14.2.4 Binary operator overload resolutionAn operation of the form x op y, where op is an overloadable binary operator, x is an expression of type X,and y is an expression of type Y, is processed as follows:• The set of candidate user-defined operators provided by X and Y for the operation operator op(x, y)is determined. The set consists of the union of the candidate operators provided by X and the candidateoperators provided by Y, each determined using the rules of §14.2.5. If X and Y are the same type, or if Xand Y are derived from a common base type, then shared candidate operators only occur in the combinedset once.• If the set of candidate user-defined operators is not empty, then this becomes the set of candidateoperators for the operation. Otherwise, the predefined binary operator op implementations become theset of candidate operators for the operation. The predefined implementations of a given operator arespecified in the description of the operator (§14.7 through §14.13).• The overload resolution rules of §14.4.2 are applied to the set of candidate operators to select the bestoperator with respect to the argument list (x, y), and this operator becomes the result of the overloadresolution process. If overload resolution fails to select a single best operator, a compile-time erroroccurs.14.2.5 Candidate user-defined operatorsGiven a type T and an operation operator op(A), where op is an overloadable operator and A is anargument list, the set of candidate user-defined operators provided by T for operator op(A) is determinedas follows:• For all operator op declarations in T, if at least one operator is applicable (§14.4.2.1) with respect tothe argument list A, then the set of candidate operators consists of all applicable operator opdeclarations in T.• Otherwise, if T is object, the set of candidate operators is empty.• Otherwise, the set of candidate operators provided by T is the set of candidate operators provided by thedirect base class of T.14.2.6 Numeric promotionsThis clause is informative.Numeric promotion consists of automatically performing certain implicit conversions of the operands of thepredefined unary and binary numeric operators. Numeric promotion is not a distinct mechanism, but ratheran effect of applying overload resolution to the predefined operators. Numeric promotion specifically doesnot affect evaluation of user-defined operators, although user-defined operators can be implemented toexhibit similar effects.As an example of numeric promotion, consider the predefined implementations of the binary * operator:int operator *(int x, int y);uint operator *(uint x, uint y);long operator *(long x, long y);ulong operator *(ulong x, ulong y);float operator *(float x, float y);double operator *(double x, double y);decimal operator *(decimal x, decimal y);127

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!