X hits on this document

1044 views

0 shares

0 downloads

0 comments

130 / 396

Chapter ‎18   Unsafe code

When a function member with a parameter array is invoked in its expanded form, the invocation is processed exactly as if an array creation expression with an array initializer (§‎7.5.10.2) was inserted around the expanded parameters. For example, given the declaration

void F(int x, int y, params object[] args);

the following invocations of the expanded form of the method

F(10, 20); F(10, 20, 30, 40); F(10, 20, 1, "hello", 3.0);

correspond exactly to

F(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 parameter array.

7.4.2 Overload resolution

Overload resolution is a compile-time mechanism for selecting the best function member to invoke given an argument list and a set of candidate function members. Overload resolution selects the function member to invoke in the following distinct contexts within C#:

Invocation of a method named in an invocation-expression (§‎7.5.5).

Invocation of an instance constructor named in an object-creation-expression (§‎7.5.10.1).

Invocation of an indexer accessor through an element-access (§‎7.5.6).

Invocation of a predefined or user-defined operator referenced in an expression (§‎7.2.3 and §‎7.2.4).

Each of these contexts defines the set of candidate function members and the list of arguments in its own unique way, as described in detail in the sections listed above. For example, the set of candidates for a method invocation does not include methods marked override (§‎7.3), and methods in a base class are not candidates if any method in a derived class is applicable (§‎7.5.5.1).

Once the candidate function members and the argument list have been identified, the selection of the best function member is the same in all cases:

Given the set of applicable candidate function members, the best function member in that set is located. If the set contains only one function member, then that function member is the best function member. Otherwise, the best function member is the one function member that is better than all other function members with respect to the given argument list, provided that each function member is compared to all other function members using the rules in §‎7.4.2.2. If there is not exactly one function member that is better than all other function members, then the function member invocation is ambiguous and a compile-time error occurs.

The following sections define the exact meanings of the terms applicable function member and better function member.

7.4.2.1 Applicable function member

A function member is said to be an applicable function member with respect to an argument list A when all of the following are true:

The number of arguments in A is identical to the number of parameters in the function member declaration.

For each argument in A, the parameter passing mode of the argument (i.e., value, ref, or out) is identical to the parameter passing mode of the corresponding parameter, and

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.117

Document info
Document views1044
Page views1044
Page last viewedSat Dec 10 10:22:18 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments