Tuesday, June 17, 2008

Operators in C#

It is important to know that C# and java support the rules of IEEE, means if you have 10.5/0 you won't get an error. It will be infinity or if you have 0.0/0.0 the result will be not a number. But if you have 10/0 then you will got an overflow error.

As you all know there are different kinds of operators. 
 ·         Relational Operators such as ==,!=,>,>=,<,<= which are used between two operands(except !=) and the result is a Boolean.
 ·         Logical operators such as &,,&&, that are used between two Boolean operands and return a boolean. It is good to point that && and  make a short circuit, means if the first operand is false the && operator returns false without checking the other operand. But if the first operand is true  operator will return true without checking the other one.
 ·         Arithmetic operators such as +,-,*,%. No need to describe them more as you are familiar with 
Besides the other operators that we don't describe them here, there are some important ones that are basic in C#.

++ Increment operator, incrementing the value by 1 (i++ is the same as i=i+1)

— Decrement operator, decrementing the value by 1 (i— is the same as i=i-1)

+= Increment assignment operator (i+=5 is the same as i=i+5)

-= Decrement assignment operator (i-=5 is the same as i=i-5)

== and != Equality and Inequality operator

% Modulus (remainder) operator. (17%5 equals 2)

Thanks to Azadeh for this post

No comments: