13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 14 Expressions14.5.5.2 Delegate invocationsFor a delegate invocation, the primary-expression of the invocation-expression must be a value of adelegate-type. Furthermore, considering the delegate-type to be a function member with the same parameterlist as the delegate-type, the delegate-type must be applicable (§14.4.2.1) with respect to the argument-list ofthe invocation-expression.The run-time processing of a delegate invocation of the form D(A), where D is a primary-expression of adelegate-type and A is an optional argument-list, consists of the following steps:• D is evaluated. If this evaluation causes an exception, no further steps are executed.• The value of D is checked to be valid. If the value of D is null, aSystem.NullReferenceException is thrown and no further steps are executed.• Otherwise, D is a reference to a delegate instance. A function member invocation (§14.4.3) is performedon the method referenced by the delegate. If the method is an instance method, the instance of theinvocation becomes the instance referenced by the delegate.14.5.6 Element accessAn element-access consists of a primary-no-array-creation-expression, followed by a “[“ token, followedby an expression-list, followed by a “]” token. The expression-list consists of one or more expressions,separated by commas.element-access:primary-no-array-creation-expression [ expression-list ]expression-list:expressionexpression-list , expressionIf the primary-no-array-creation-expression of an element-access is a value of an array-type, the elementaccessis an array access (§14.5.6.1). Otherwise, the primary-no-array-creation-expression must be avariable or value of a class, struct, or interface type that has one or more indexer members, in which case theelement-access is an indexer access (§14.5.6.2).14.5.6.1 Array accessFor an array access, the primary-no-array-creation-expression of the element-access must be a value of anarray-type. The number of expressions in the expression-list must be the same as the rank of the array-type,and each expression must be of type int, uint, long, ulong, or of a type that can be implicitly convertedto one or more of these types.The result of evaluating an array access is a variable of the element type of the array, namely the arrayelement selected by the value(s) of the expression(s) in the expression-list.The run-time processing of an array access of the form P[A], where P is a primary-no-array-creationexpressionof an array-type and A is an expression-list, consists of the following steps:• P is evaluated. If this evaluation causes an exception, no further steps are executed.• The index expressions of the expression-list are evaluated in order, from left to right. Followingevaluation of each index expression, an implicit conversion (§13.1) to one of the following types isperformed: int, uint, long, ulong. The first type in this list for which an implicit conversion exists ischosen. For instance, if the index expression is of type short then an implicit conversion to int isperformed, since implicit conversions from short to int and from short to long are possible. Ifevaluation of an index expression or the subsequent implicit conversion causes an exception, then nofurther index expressions are evaluated and no further steps are executed.• The value of P is checked to be valid. If the value of P is null, aSystem.NullReferenceException is thrown and no further steps are executed.143

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!