old-code/monodoc/ecma334/14.4.2.xml

7 строки
2.4 KiB
XML

<?xml version="1.0"?>
<clause number="14.4.2" title="Overload resolution">
<paragraph>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#: <list><list_item> Invocation of a method named in an <non_terminal where="14.5.5">invocation-expression</non_terminal> (<hyperlink>14.5.5</hyperlink>). </list_item><list_item> Invocation of an instance constructor named in an <non_terminal where="14.5.10.1">object-creation-expression</non_terminal> (<hyperlink>14.5.10.1</hyperlink>). </list_item><list_item> Invocation of an indexer accessor through an <non_terminal where="14.5.6">element-access</non_terminal> (<hyperlink>14.5.6</hyperlink>). </list_item><list_item> Invocation of a predefined or user-defined operator referenced in an expression (<hyperlink>14.2.3</hyperlink> and <hyperlink>14.2.4</hyperlink>). </list_item></list></paragraph>
<paragraph>Each of these contexts defines the set of candidate function members and the list of arguments in its own unique way. However, 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: <list><list_item> First, the set of candidate function members is reduced to those function members that are applicable with respect to the given argument list (<hyperlink>14.4.2.1</hyperlink>). If this reduced set is empty, a compile-time error occurs. </list_item><list_item> Then, 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 <hyperlink>14.4.2.2</hyperlink>. 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. </list_item></list></paragraph>
<paragraph>The following sections define the exact meanings of the terms applicable function member and better function member. </paragraph>
</clause>