14.3 Member lookup

博客介绍了类型中成员查找的过程,它可能在表达式求值时出现。成员查找先构建可访问成员集,排除含override修饰符的声明;再移除被隐藏的成员;最后确定查找结果。单继承查找无歧义,多继承接口查找可能有歧义。
A member lookup is the process whereby the meaning of a name in the context
of a type is determined. A
member lookup may occur as part of evaluating a simple-name (?4.5.2) or a
member-access (?4.5.4) in an
expression.
A member lookup of a name N in a type T is processed as follows:
?First, the set of all accessible (?0.5) members named N declared in T
and the base types (?4.3.1) of T
is constructed. Declarations that include an override modifier are excluded
from the set. If no
members named N exist and are accessible, then the lookup produces no
match, and the following steps
are not evaluated.
?Next, members that are hidden by other members are removed from the set.
For every member S.M in
the set, where S is the type in which the member M is declared, the
following rules are applied:
If M is a constant, field, property, event, type, or enumeration member,
then all members declared in a base
type of S are removed from the set.
If M is a method, then all non-method members declared in a base type of S
are removed from the set, and all
methods with the same signature as M declared in a base type of S are
removed from the set.
?Finally, having removed hidden members, the result of the lookup is
determined:
If the set consists of a single non-method member, then this member is the
result of the lookup.
Otherwise, if the set contains only methods, then this group of methods is
the result of the lookup.
Otherwise, the lookup is ambiguous, and a compile-time error occurs (this
situation can only occur for a
member lookup in an interface that has multiple direct base interfaces).
For member lookups in types other than interfaces, and member lookups in
interfaces that are strictly singleinheritance
(each interface in the inheritance chain has exactly zero or one direct
base interface), the effect of
the lookup rules is simply that derived members hide base members with the
same name or signature. Such
single-inheritance lookups are never ambiguous. The ambiguities that can
possibly arise from member
lookups in multiple-inheritance interfaces are described in ?0.2.5.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值