Professional Documents
Culture Documents
(C#) Chapter - 5
(C#) Chapter - 5
one or more values to createa result. The values the operator acts upon
are operands. For example, in the following statement,the operator is +
(addition), the operands are B and C, and the result is assigned to the
variable A.
A=B+C
C# operators :
1. Arithmetic
2. concatenation,
3. comparison,
4. logical,
5. Bitwise,
6. Conditional ,
7. And Assignment
Arithmetic Operators
Concatenation Operator
• The + symbol represents both numeric addition
and string concatenation. The following code
shows an example of string concatenation.
string firstname = "Rod";
string lastname = "Stephens";
string name = firstname + ' ' + lastname;
Comparison Operators
Comparison operators compare one value to another
and return a boolean value (true or false), depending
on the result.
Logical Operators
Comparison operators compare one value to another
and return a boolean value (true or false), depending
on the result.
Bitwise Operators
Bitwise operators work much like logical operators do, except they
compare integer values one bit at a time.
The bitwise negation operator ~ flips the bits in its operand from 1 to
0 and vice versa. The following shows an example:
~10110111
= 01001000
The bitwise And operator & places a 1 in a result bit if both of its
operands have a 1 in that position. The following shows an example:
10101010
& 00110110
= 00100010
The bitwise Or operator | places a 1 in the result if either of its
operands has a 1 in the corresponding position. The following
shows an example:
10101010
| 00110110
= 10111110