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

Chapter 14 Expressions

1[Note: Also note that it is not possible for an operand to be of type ulong when the other operand is of a

2signed integral type. The reason is that no integral type exists that can represent the full range of ulong

3as well as the signed integral types. end note]

4In both of the above cases, a cast expression can be used to explicitly convert one operand to a type that is

5compatible with the other operand.

6[Example: In the following code

7decimal AddPercent(decimal x, double percent) {

8return x * (1.0 + percent / 100.0);

9}

10a compile-time error occurs because a decimal cannot be multiplied by a double. The error is resolved by

11explicitly converting the second operand to decimal, as follows:

12decimal AddPercent(decimal x, double percent) {

13return x * (decimal)(1.0 + percent / 100.0);

14}

15end example]

16End of informative text.

1714.3 Member lookup

18A member lookup is the process whereby the meaning of a name in the context of a type is determined. A

19member lookup can occur as part of evaluating a simple-name (§14.5.2) or a member-access (§14.5.4) in an

20expression.

21Member lookup considers not only the name of a member but also the number of type parameters the

22member has and whether the member is accessible. For the purposes of member lookup, generic methods

23and nested generic types have the number of type parameters indicated in their respective declarations and

24all other members have zero type parameters.

25A member lookup of a name N with K type parameters in a type T is processed as follows:

26First, a set of accessible members named N is determined:

27o If T is a type parameter, then the set is the union of the sets of accessible members named N in each

28of the types specified as a primary constraint or secondary constraint (§26.7) for T, along with the

29set of accessible members named N in object.

30o Otherwise, the set consists of all accessible (§10.5) members named N in T, including inherited

31members and the accessible members named N in object. If T is a constructed type, the set of

32members is obtained by substituting type arguments as described in §26.5.4. Members that include

33an override modifier are excluded from the set.

34Next, if the set of accessible members is empty, the member lookup does not produce a match and no

35further steps are taken.

36Next, if K is zero, remove all nested types whose declaration included type parameters. If K is not zero,

37remove all members with a different number of type parameters. Note that when K is zero, we do not

38remove all methods having type parameters, since the type inference process (§26.6.4) might be able to

39infer the type arguments.

40Next, members that are hidden by other members are removed from the set. Members that are removed

41during this step may still cause other members to be removed. For every member S.M in the set, where S

42is the type in which the member M is declared, the following rules are applied:

43o If M is a constant, field, property, event, enumeration member, or type declaration then all members

44declared in a base type of S are removed from the set.

45o If M is a method, then all non-method members declared in a base type of S are removed from the

46set.

151

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