Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayAccess vs. ArrayIndex in Expression Tree

What is the difference between these 2? From the API documentation it seems like they were meant to do the exact same thing.

ArrayAccess

vs.

ArrayIndex

In which case they seem redundant, so I must be missing something here.

like image 899
Alwyn Avatar asked Feb 20 '13 06:02

Alwyn


1 Answers

Edit: My initial answer was so badly wrong that I'm trying again.

Expression.ArrayAccess returns an IndexExpression which can be used to get or set the value of an element in an array.

Expression.ArrayIndex returns either a BinaryExpression or a MethodCallExpression depending on the rank (number of dimensions) of the provided array expression. The returned expression can then be used to read a value from the array.

So ArrayAccess gives you an expression that provides both read and write access to the array data, while ArrayIndex gives you read access only.

like image 87
Corey Avatar answered Nov 02 '22 07:11

Corey