ArrayAccess vs. ArrayIndex in Expression Tree

.net c# expression-trees linq

Question

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.

Accepted Answer

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.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why