C# – Arithmetic Operators

Let’s handle today arithmetic operators. I always try to explain as easy as possible.

= NOT Not equality, it is assigment

Math operators is + – * /

Addition assigment

total = total + 5;

total += 5;

Increment operator  i++;

Decrement operator i–;

Beware of order of precedence (use parenthesis)

Beware of down casting (you will lose precision)

Beware of overflow (use bigger types)

To make overflow throw an exception

checked{

/some arithmetic operation that could potentially overflow

}

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.