What is operator associative in C#?

 Posted by Goud.Kv on 9/3/2014 | Category: C# Interview questions | Views: 411 | Points: 40
Answer:

Associativity comes in to the picture when we have same operators in an expression. It tells the order of evaluation that which operator should work first.

Binary operators are left associative (executes from left to right).
Example,
4 + 3 + 2
In the above example, first the sum is performed between 4 and 3. Then the result will be summed to 2.

Assignment, conditional, lambda and null coalescing operators are right associative (executes from right to left).
Example,
x = y = z = 6
In the above example, 6 is first assigned to z and then to y and so on.


Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response