Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C# documentation C# operators and expressions - C# reference | Microsoft Docs[^] had the following to say concerning the evaluation of operands and operators in an expression:
Unrelated to operator precedence and associativity, operands in an expression are evaluated from left to right. The following examples demonstrate the order in which operators and operands are evaluated:

Expression:
C#
a + b

Order of Evaluation of the above expression: a, b, +

Expression:
C#
a + b * c

Order of Evaluation of the above expression: a, b, c, *, +

Expression:
C#
a / b + c * d

Order of Evaluation of the above expression: a, b, /, c, d, *, +

Expression:
C#
a / (b + c) * d

Order of Evaluation of the above expression: a, b, c, +, /, d, *


Questions:
- What does it mean when an operand (e.g. a, b, c, d) is evaluated?
- Also what does the order of evaluation of a, b, c, +, /, d, * mean?

What I have tried:

Documentation is unclear to me. Perhaps someone can help me understand what is said in the documentation. Thanks in advance :)
Posted
Updated 7-Dec-21 22:24pm
v2
Comments
Dave Kreskowiak 7-Dec-21 21:19pm    
Hi Jake! Why do you keep creating socket puppet accounts? We know it's you.
Dave Kreskowiak 7-Dec-21 22:01pm    
No, thanks.

I'm not the one who needs it.

1 solution

Microsoft, and others, spend thousands of dollars creating and publishing documentation specifically aimed at people looking for answers. It is high time you started to make use of it. And, as Dave already stated, please stop creating these sock puppet accounts.

[edit]
What does it mean when an operand (e.g. a, b, c, d) is evaluated?

It means that each expression is evaluated from whatever is written into a single numeric value. For example if a is the string "sin(45)". then the 45 needs to be converted to an integer, and then the sin function needs to be called on that value to get the 'real' value of a.
- Also what does the order of evaluation of a, b, c, +, /, d, * mean?

It is stack based calculation.
- The values of a,b and c are pushed onto the stack.
- When the '+' is found, b and c (the top two values) are popped off the stack and added together.
- The result (bc) is pushed back. So now you have two values a and sum(bc).
- Next the division operator is examined, and a and bc are poppped off the stack, and a is divided by bc. The result (abc) is pushed onto the stack.
- Next d is pushed onto the stack, so now we have two values: abc and d.
- Next the multiplication operator is examined. The two values are popped off the stack and multiplied together. The final result is abcd.

Try it yourself with some real numbers to see how it works.

[/edit]
 
Share this answer
 
v2
Comments
[no name] 8-Dec-21 4:31am    
Hi, thanks for the feedback :) In response to what you are saying I try to make use of it by understanding what it says. In my post I reference the text and examples that I don't understand. Hopefully to obtain some clarification here. What's wrong about that?
Richard MacCutchan 8-Dec-21 5:24am    
See my update.
OriginalGriff 8-Dec-21 4:34am    
Trolls don't need to learn - this one already knows everything. :sigh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900