Wednesday, 4 January 2012

Arithmetic

Operators
C# operators and their precedence closely resemble the operators in other languages of the C family.

Similar to C++, classes can overload most operators, defining or redefining the behavior of the operators in contexts where the first argument of that operator is an instance of
that class, but doing so is often discouraged for clarity.
Following are the built-in behaviors of C# operators.

Arithmetic
The following arithmetic operators operate on numeric operands (arguments a and b in the "sample usage" below).
Sampleus- Read Explanation
age
a + b a plus b The binary operator + returns the sum of its arguments.
a - b a minus b The binary operator - returns the difference between its arguments.
a * b a times b The binary operator * returns the multiplicative product of
its arguments.
The binary operator / returns the quotient of its arguments.
a / b a divided by b If both of its operators are integers, it obtains that quotient
using integer division (i.e. it drops any resulting remainder).
The binary operator % operates only on integer arguments.
a % b a mod b It returns the remainder of integer division of those arguments.
(See modular arithmetic.)
a++ a plus plus The unary operator ++ operates only on arguments that have
an l-value. When placed after its argument, it increments
that argument by 1 and returns the value of that argument
before it was incremented.
++a plus plus a The unary operator ++ operates only on arguments that have
an l-value. When placed before its argument, it increments
that argument by 1 and returns the resulting value.
a-- a minus minus The unary operator -- operates only on arguments that have
an l-value. When placed after its argument, it decrements
that argument by 1 and returns the value of that argument
before it was decremented.
The unary operator -- operates only on arguments that have
a --a minus minus an l-value. When placed before its argument, it decrements
that argument by 1 and returns the resulting value.