TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  11@407Checked automatically with code checker

Synopsis:Write unary, increment, decrement, function call, subscript, and access operators together with their operands; insert spaces around all other operators
Language:C#
Severity Level:10
Category:Coding style


Description:

OPERATORS & OPERANDS

Operators are operations that are performed, operands are the arguments or expressions of these operations.

E.g. in "int i = (count + 1)":

  • there is an assignment operator '=', with operands 'i' and '(count + 1)'
  • there is an Add operator '+', with operands 'count' and the literal '1'

Depending on the amount of operands it works on, an operator is called:

  • unary -> works on a single operand, e.g. "-1", "++count", "!isClosed" and "sizeof(int)"
  • binary -> works on two operands, e.g. "a - b", "(isOnLine && hasImages)" and "(a <= b)"
  • ternary -> works on three operands, e.g. the conditional operator '?' as in"((hasImages) ? firstImageIndex : NoImageIndex)"

Next to that an operator can be:

  • bitwise -> i.e. applies to the 'bit-pattern' of it's operand(s)
  • comparison -> i.e. compares the operands
  • logical -> i.e. performs a logical evaluation of it's operands and returns a boolean result (!, &&, ||
  • mathematical -> i.e. perfoms a mathematical operation (++, --, +, -, /, *)

CODING RULES

The following style rules apply for the operators in the table below and their operands:

  • It is not allowed to add spaces in between these operators and their operands.
  • It is not allowed to separate a unary operator from its operand with a newline.

Note: the latter rule does not apply to the binary versions of the '&', '*', '+' and '-' operators.

For all other operators (and their operands) these rules do NOT apply !

unary:& * + - ~ !
increment and decrement:-- ++
function call and subscript:() []
access:.

EXAMPLES

a = -- b;	// wrong
a = --c;	// right

a = -b - c;	// right
a = (b1 + b2) +
       (c1 - c2) +
        d - e - f;	// also fine: make it as readable as possible