To understand the order of operations, you need to remember that the cast will be applied to the object to the right, but the rules that affect WHEN it depends on MSDN The priority of operators and associativity
(Dictionary<String, String>)((Object[])e.Result)[1];
becomes
Object[] cast1 = (Object[]) e.Result;
The casting operation is grouped into the category “Unary operators”, which is a lower priority than the index - [], which is located in the category “Primary expressions”.
In the original line, - () is needed around cast: ((Object []) e.Result), because indexer - [] is applied immediately to the object on the left as the first priority. Without the surrounding () cast, it will be applied AFTER the indexer, and since the e.Result (probably?) Is an Object of type, this will happen at compile time. Without () the line will look like this:
(Object[])e.Result[1]
Which is invalid.
((Object[])e.Result)[1]
ensures that e.Result will distinguish first the type Object [], and then the indexer is used to access the first element.
The second cast turns the first casted object [] element (in my example cast 1) into a dictionary
Dictionary<String, String> cast2 = (Dictionary<String, String>) cast1[1];
source share