Send comments on this topic. |
|
Cause
Rule Description
int x = 5 + y * b / 6 % z - 2;
Although this code is legal, it is not highly readable or maintainable. In order to achieve full understanding of this code, the developer must know and understand the basic operator precedence rules in C#.
This rule is intended to increase the readability and maintainability of this type of code, and to reduce the risk of introducing bugs later, by forcing the developer to insert parenthesis to explicitly declare the operator precedence. The example below shows multiple arithmetic operations surrounded by parenthesis:
int x = 5 + (y * ((b / 6) % z)) - 2;
Inserting parenthesis makes the code more obvious and easy to understand, and removes the need for the reader to make assumptions about the code.
How to Fix Violations
© Microsoft Corporation. All Rights Reserved.