Signature and overload

Source: Internet
Author: User

Methods, instance constructors, indexers, and operators are characterized by their signatures:

A Method signature consists of the method name and the type and type (value, reference, or output) of each of its parameters (in the order from left to right. Note that the method signature does not contain either the return type or the Params modifier (which can be used for rightmost parameters ).

The instance constructor signature is composed of the type and type (value, reference, or output) of each of its parameters (in the order from left to right. Specifically, the instance constructor signature does not contain the Params modifier that can be specified for the rightmost parameter.

The index signature is composed of each of its parameters (in the order from left to right. Specifically, the index signature does not contain the element type.

The operator signature is composed of the Operator name and each of its parameters (in the order from left to right. Specifically, the signature of an operator does not contain the result type.

Signature is a mechanism to overload members of classes, structures, and interfaces:

Method overloading allows classes, structures, or interfaces to declare multiple methods with the same name, provided that their signatures are unique in the class, structure, or interface.
An instance constructor overload allows a class or structure to declare multiple instance constructor, provided that their signatures are unique in this class or structure.
The indexer overload allows the class, structure, or interface to declare multiple indexers. The condition is that their signatures are unique in the class, structure, or interface.
Operator Overloading allows classes or structures to declare multiple operators with the same name. The condition is that their signatures are unique in this class or structure.
The following example shows a set of overloaded method declarations and their signatures.

Interface itest
{
Void F (); // F ()
Void F (int x); // F (INT)
Void F (ref int X); // F (ref INT)
Void F (int x, int y); // F (INT, INT)
Int F (string S); // F (string)
Int F (int x); // F (INT) Error
Void F (string [] A); // F (string [])
Void F (Params string [] A); // F (string []) Error
}

Note that all ref and out parameter modifiers (section 10.5.1) are part of the signature. Therefore, both the F (INT) and F (ref INT) signatures are unique. Note that the return type and Params modifier are not part of the signature, so it is not possible to implement overloading only based on the return type or whether the Params modifier exists. Therefore, the declarations on Methods F (INT) and F (Params string []) listed above will cause compilation errors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.