13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONWhen a function member with a parameter array is invoked in its expanded form, the invocation isprocessed exactly as if an array creation expression with an array initializer (§14.5.10.2) was inserted aroundthe expanded parameters. [Example: For example, given the declarationvoid F(int x, int y, params object[] args);the following invocations of the expanded form of the methodF(10, 20);F(10, 20, 30, 40);F(10, 20, 1, "hello", 3.0);correspond exactly toF(10, 20, new object[] {});F(10, 20, new object[] {30, 40});F(10, 20, new object[] {1, "hello", 3.0});In particular, note that an empty array is created when there are zero arguments given for the parameterarray. end example]14.4.2 Overload resolutionOverload resolution is a compile-time mechanism for selecting the best function member to invoke given anargument list and a set of candidate function members. Overload resolution selects the function member toinvoke in the following distinct contexts within <strong>C#</strong>:• Invocation of a method named in an invocation-expression (§14.5.5).• Invocation of an instance constructor named in an object-creation-expression (§14.5.10.1).• Invocation of an indexer accessor through an element-access (§14.5.6).• Invocation of a predefined or user-defined operator referenced in an expression (§14.2.3 and §14.2.4).Each of these contexts defines the set of candidate function members and the list of arguments in its ownunique way. However, once the candidate function members and the argument list have been identified, theselection of the best function member is the same in all cases:• First, the set of candidate function members is reduced to those function members that are applicablewith respect to the given argument list (§14.4.2.1). If this reduced set is empty, a compile-time erroroccurs.• Then, given the set of applicable candidate function members, the best function member in that set islocated. If the set contains only one function member, then that function member is the best functionmember. Otherwise, the best function member is the one function member that is better than all otherfunction members with respect to the given argument list, provided that each function member iscompared to all other function members using the rules in §14.4.2.2. If there is not exactly one functionmember that is better than all other function members, then the function member invocation isambiguous and a compile-time error occurs.The following sections define the exact meanings of the terms applicable function member and betterfunction member.14.4.2.1 Applicable function memberA function member is said to be an applicable function member with respect to an argument list A when allof the following are true:• The number of arguments in A is identical to the number of parameters in the function memberdeclaration.• For each argument in A, the parameter passing mode of the argument (i.e., value, ref, or out) isidentical to the parameter passing mode of the corresponding parameter, and134

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

Saved successfully!

Ooh no, something went wrong!