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

C# LANGUAGE SPECIFICATION

1Otherwise, the expanded form is applicable if for each argument in A the parameter passing mode of the

2argument is identical to the parameter passing mode of the corresponding parameter, and

3o for a fixed value parameter or a value parameter created by the expansion, an implicit conversion

4(§13.1) exists from the type of the argument to the type of the corresponding parameter, or

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

6parameter.

714.4.2.2 Better function member

8Given an argument list A with a set of argument types A1, A2, …, AN and two applicable function members MP

9and MQ with parameter types P1, P2, …, PN and Q1, Q2, …, QN, MP is defined to be a better function member

10than MQ if

11for each argument, the implicit conversion from AX to PX is not worse than the implicit conversion from

12AX to QX, and

13for at least one argument, the conversion from AX to PX is better than the conversion from AX to QX.

14When performing this evaluation, if MP or MQ is applicable in its expanded form, then PX or QX refers to a

15parameter in the expanded form of the parameter list.

1614.4.2.3 Better conversion

17Given an implicit conversion C1 that converts from a type S to a type T1, and an implicit conversion C2 that

18converts from a type S to a type T2, the better conversion of the two conversions is determined as follows:

19If T1 and T2 are the same type, neither conversion is better.

20If S is T1, C1 is the better conversion.

21If S is T2, C2 is the better conversion.

22If an implicit conversion from T1 to T2 exists, and no implicit conversion from T2 to T1 exists, C1 is the

23better conversion.

24If an implicit conversion from T2 to T1 exists, and no implicit conversion from T1 to T2 exists, C2 is the

25better conversion.

26If T1 is sbyte and T2 is byte, ushort, uint, or ulong, C1 is the better conversion.

27If T2 is sbyte and T1 is byte, ushort, uint, or ulong, C2 is the better conversion.

28If T1 is short and T2 is ushort, uint, or ulong, C1 is the better conversion.

29If T2 is short and T1 is ushort, uint, or ulong, C2 is the better conversion.

30If T1 is int and T2 is uint, or ulong, C1 is the better conversion.

31If T2 is int and T1 is uint, or ulong, C2 is the better conversion.

32If T1 is long and T2 is ulong, C1 is the better conversion.

33If T2 is long and T1 is ulong, C2 is the better conversion.

34Otherwise, neither conversion is better.

35If an implicit conversion C1 is defined by these rules to be a better conversion than an implicit conversion C2,

36then it is also the case that C2 is a worse conversion than C1.

3714.4.3 Function member invocation

38This subclause describes the process that takes place at run-time to invoke a particular function member. It is

39assumed that a compile-time process has already determined the particular member to invoke, possibly by

40applying overload resolution to a set of candidate function members.

158

Chapter 14 Expressions

1For purposes of describing the invocation process, function members are divided into two categories:

2Static function members. These are static methods, static property accessors, and user-defined operators.

3Static function members are always non-virtual.

4Instance function members. These are instance methods, instance constructors, instance property

5accessors, and indexer accessors. Instance function members are either non-virtual or virtual, and are

6always invoked on a particular instance. The instance is computed by an instance expression, and it

7becomes accessible within the function member as this (§14.5.7). For an instance constructor, the

8instance expression is taken to be the newly allocated object.

9The run-time processing of a function member invocation consists of the following steps, where M is the

10function member and, if M is an instance member, E is the instance expression:

11If M is a static function member:

12o The argument list is evaluated as described in §14.4.1.

13o M is invoked.

14If M is an instance function member declared in a value-type:

15o E is evaluated. If this evaluation causes an exception, then no further steps are executed. For an

16instance constructor, this evaluation consists of allocating the storage (typically from an execution

17stack) for the new object. In this case E is classified as a variable.

18o If E is not classified as a variable, then a temporary local variable of E’s type is created and the value

19of E is assigned to that variable. E is then reclassified as a reference to that temporary local variable.

20The temporary variable is accessible as this within M, but not in any other way. Thus, only when E

21is a true variable is it possible for the caller to observe the changes that M makes to this.

22o The argument list is evaluated as described in §14.4.1.

23o M is invoked. The variable referenced by E becomes the variable referenced by this.

24If M is an instance function member declared in a reference-type:

25o E is evaluated. If this evaluation causes an exception, then no further steps are executed. For an

26instance constructor, this evaluation consists of allocating (typically from a garbage collected heap)

27the storage for the new object.

28o The argument list is evaluated as described in §14.4.1.

29o If the type of E is a value-type, a boxing conversion (§11.3.1) is performed to convert E to type

30System.Enum (if E is an enum) or System.ValueType, and E is considered to be of this type in

31the following steps. [Note: In this case, M could only be a member of System.Enum,

32System.ValueType, or System.Object. end note]

33o The value of E is checked to be valid. If the value of E is null, a

34System.NullReferenceException is thrown and no further steps are executed.

35o The function member implementation to invoke is determined:

36If the compile-time type of E is an interface, the function member to invoke is the

37

implementation of M provided by the run-time type of the instance referenced by E. This

38

function member is determined by applying the interface mapping rules (§20.4.2).

39

Otherwise, if M is a virtual function member, the function member to invoke is the

40

implementation of M provided by the run-time type of the instance referenced by E. This

41

function member is determined by applying the rules for determining the most derived

42

implementation (§17.5.3) of M with respect to the run-time type of the instance referenced by E.

43

Otherwise, M is a non-virtual function member, and the function member to invoke is M itself.

159

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