Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

Chapter 14 Expressions

114.4.2 Overload resolution

2Overload resolution is a compile-time mechanism for selecting the best function member to invoke given an

3argument list and a set of candidate function members. Overload resolution selects the function member to

4invoke in the following distinct contexts within C#:

5Invocation of a method named in an invocation-expression (§14.5.5).

6Invocation of an instance constructor named in an object-creation-expression (§14.5.10.1).

7Invocation of an indexer accessor through an element-access (§14.5.6).

8Invocation of a predefined or user-defined operator referenced in an expression (§14.2.3 and §14.2.4).

9Each of these contexts defines the set of candidate function members and the list of arguments in its own

10unique way. However, once the candidate function members and the argument list have been identified, the

11selection of the best function member is the same in all cases:

12First, the set of candidate function members is reduced to those function members that are applicable

13with respect to the given argument list (§14.4.2.1). If this reduced set is empty, a compile-time error

14occurs.

15Then, given the set of applicable candidate function members, the best function member in that set is

16located. If the set contains only one function member, then that function member is the best function

17member. Otherwise, the best function member is the one function member that is better than all other

18function members with respect to the given argument list, provided that each function member is

19compared to all other function members using the rules in §14.4.2.2. If there is not exactly one function

20member that is better than all other function members, then the function member invocation is

21ambiguous and a compile-time error occurs.

22The following subclauses define the exact meanings of the terms applicable function member and better

23function member.

2414.4.2.1 Applicable function member

25A function member is said to be an applicable function member with respect to an argument list A when all

26of the following are true:

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

28declaration.

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

30identical to the parameter passing mode of the corresponding parameter, and

31o for a value parameter or a parameter array, an implicit conversion (§13.1) exists from the type of the

32argument to the type of the corresponding parameter, or

33o for a ref or out parameter, the type of the argument is identical to the type of the corresponding

34parameter. [Note: After all, a ref or out parameter is an alias for the argument passed. end note]

35For a function member that includes a parameter array, if the function member is applicable by the above

36rules, it is said to be applicable in its normal form. If a function member that includes a parameter array is

37not applicable in its normal form, the function member might instead be applicable in its expanded form:

38The expanded form is constructed by replacing the parameter array in the function member declaration

39with zero or more value parameters of the element type of the parameter array such that the number of

40arguments in the argument list A matches the total number of parameters. If A has fewer arguments than

41the number of fixed parameters in the function member declaration, the expanded form of the function

42member cannot be constructed and is thus not applicable.

43If the class, struct, or interface in which the function member is declared already contains another

44applicable function member with the same signature as the expanded form, the expanded form is not

45applicable.

157

Соседние файлы в предмете Электротехника