2.4. Variable Operations
You can use all the standard types of variable operations in C#. When working with numbers, you can use various math symbols, as listed in Table 2-2. C# follows the conventional order of operations, performing exponentiation first, followed by multiplication and division and then addition and subtraction. You can also control order by grouping subexpressions with parentheses:
int number; number = 4 + 2 * 3; // number will be 10. number = (4 + 2) * 3; // number will be 18.
Operator | Description | Example |
---|---|---|
+ | Addition | 1 + 1 = 2 |
- | Subtraction (and to indicate negative numbers) | 5 - 2 = 3 |
* | Multiplication | 2 * 5 = 10 |
/ | Division | 5.0 / 2 = 2.5 |
% | Gets the remainder left after integer division | 7 % 3 = 1 |
Division can ...
Get Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.