Operators and expressions
Combine values with arithmetic, comparisons, logic, and conditional expressions.
On this page
A coin adds one to a count, multiplies that count by a score value, and checks whether a goal condition has been met. Operators turn those small values into a decision.
The problem
Section titled “The problem”ScoreCounter.AddCoins uses += twice. The second assignment combines multiplication and addition while preserving the order C# evaluates them.
When to reach for it
Section titled “When to reach for it”Use arithmetic for numbers, comparisons for decisions, and logical operators to combine booleans. The conditional ?: chooses one of two values. Null-coalescing ?? supplies a fallback. Null-conditional access ?. or ?[ guards the receiving pin and skips the access when the receiver is null.
Round Trip models a compound assignment as a SET fed by an operation. Score += amount is a Score read flowing through Add and back into the Score SET. The source spelling remains += while that operation still reads the same value it sets.
An operation produces a value and never runs on its own, so the menu that opens when you drop a wire from an execution pin onto empty canvas leaves out the arithmetic, Concat, comparison, and logical rows. Place them from empty canvas or from a data pin, then wire their result into the statement that uses it.
See it
Section titled “See it”
Coins += count and the score calculation as a read feeding an operation that feeds a SET.- Right-click empty canvas and open the operators category.
- Pick an arithmetic operation such as Add, Subtract, Multiply, Divide, or Modulo. Integer inputs also offer bitwise and shift operations.
- To join text, pick Concat. Its result is a
stringfrom the start, and either side can take a string or another value, as in"score: " + points. - Fill the left and right pins with wires or literals. The result pin takes its type from the operands.
- For a boolean result, choose a comparison such as Equals, Greater Than, or Less Than, or combine booleans with And and Or.
- Use a conditional value when one condition selects between two results. Use a coalescing value when a missing left value should fall back to the right.
- To alter an existing operation, right-click it and choose change operator. The offered choices are filtered by the operand types. Concat, comparison and logical operations have no change operator row.
- Connect an operation back into the SET for the same target when you want read-modify-write behavior.
- Press Compile. Round Trip recomposes the containing statement with C# precedence and required parentheses.
What it writes
Section titled “What it writes”When it goes wrong
Section titled “When it goes wrong”When it goes wrong
| Symptom | Check | Fix |
|---|---|---|
| An operator choice is missing | Check the operand types. | Connect compatible values first, then open change operator again. |
| Compile reports a missing operand | Look for a hollow left or right pin. | Wire or type every required operand. |
| A compound assignment becomes longhand | See whether the operation still reads the same target the SET writes. | Restore that read if the compound meaning is intended. |