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 (?4.5.5).
?Invocation of an instance constructor named in an
object-creation-expression (?4.5.10.1).
?Invocation of an indexer accessor through an element-access (?4.5.6).
?Invocation of a predefined or user-defined operator referenced in an
expression (?4.2.3 and ?4.2.4).
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:
?First, the set of candidate function members is reduced to those function
members that are applicable
with respect to the given argument list (?4.4.2.1). If this reduced set is
empty, a compile-time error
occurs.
?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 ?4.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.
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 (?4.5.5).
?Invocation of an instance constructor named in an
object-creation-expression (?4.5.10.1).
?Invocation of an indexer accessor through an element-access (?4.5.6).
?Invocation of a predefined or user-defined operator referenced in an
expression (?4.2.3 and ?4.2.4).
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:
?First, the set of candidate function members is reduced to those function
members that are applicable
with respect to the given argument list (?4.4.2.1). If this reduced set is
empty, a compile-time error
occurs.
?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 ?4.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.
C#中的重载解析
本文介绍了C#中重载解析的基本概念,这是一种编译时机制,用于从候选成员集中选择最佳函数成员来调用。文章详细解释了不同上下文中重载解析的应用,包括方法调用、实例构造函数调用等,并说明了如何确定适用的候选函数成员及如何选择最佳函数成员。
2025

被折叠的 条评论
为什么被折叠?



