What changes when you trace C#
| Rule | Example | In the table |
| Dividing two ints gives an int | 7 / 2 is 3, 7 / 2.0 is 3.5 | double d = 7 / 2; stores 3, because the division happens first |
| A for loop's variable passes its limit | for (int i = 1; i <= 5; i++) | A last row with i = 6 |
| Casting to int cuts off the decimals | (int)2.7 is 2 | Convert.ToInt32(2.7) rounds instead, to 3 |
| Rounding goes to the even number | Math.Round(2.5) is 2 | Math.Round(3.5) is 4 |
| A whole-number double prints without .0 | Console.WriteLine(3.0) prints 3 | Write 3, not 3.0 |
| int wraps round when it overflows | 2147483647 + 1 | -2147483648 |
Console.Write has no new line | Console.Write("Name: ") | The prompt is output, on its own row |
ref and out change the caller's variable | Swap(ref x, ref y) | The parameter and the caller's variable change on the same row |
| A compile error stops the whole program | int x = 3.5; | No table, and the compiler's message, such as CS0266 |
Programs can be top-level statements or a class with a static Main. Methods printed without their class, as exam papers often show them, are read as the members of one. Supported: int, long, double, float, char, bool and string, arrays including two-dimensional ones, List, Dictionary, Stack and Queue, for, foreach, while, do while, switch, static methods with ref and out, recursion, try and catch, string formatting and int.TryParse. Not supported: classes of your own, properties, LINQ queries, lambdas and Random, because a random value is different on every run.