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


/some arithmetic operation that could potentially overflow



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: