C # Complete Manual (04)

xiaoxiao2021-03-06  97

9.1 Operator Overrive Foundation

There are two forms of operator methods: a corresponding one-membered operator, a corresponding binary operator. The basic form of the two-secondary operator method is:

Public Static Re-Type Operator OP (Param-Type Operand)

{

}

with

Public Static Re-Type Op (param-type1 operand1, param-type1 operand2)

{

}

For one yuan operator, the type of opera must be the same as the type of class defined the operator. For binary operators, at least one of the operands must write the same type of class that defines the class of the operator.

The operator parameter must not use the REF modifier or OUT modifier.

When heavy is overloaded or, it is not possible to distinguish between (or -) pre-forms or rear forms.

9.3 Overloading relationship operator

There is an important constraint that must be overloaded.

9.6 conversion operator

There are two forms of conversion operators: implicit and explicit. The basic forms are:

Public Static Operator Implicit Target-Type (Source-Type V) {Return Value;}

Public static operator explicit target-type (source-type v) {returnizalue;}

转载请注明原文地址:https://www.9cbs.com/read-122891.html

New Post(0)