C sharp - Arithmetic and Logical Operators in C#
Arithmetic Operators in C#
Definition:
Arithmetic operators are used to perform basic mathematical operations.
Operator | Name | Description | Example (int a = 10, b = 3; ) |
Result |
---|---|---|---|---|
+ |
Addition | Adds two operands | a + b |
13 |
- |
Subtraction | Subtracts second from first | a - b |
7 |
* |
Multiplication | Multiplies operands | a * b |
30 |
/ |
Division | Divides first by second | a / b |
3 |
% |
Modulus | Returns remainder of division | a % b |
1 |
Logical Operators in C#
Definition:
Logical operators are used to perform logical operations, mostly with boolean (true
/ false
) values.
Operator | Name | Description | Example (bool x = true, y = false; ) |
Result |
---|---|---|---|---|
&& |
Logical AND | True if both operands are true | x && y |
false |
` | ` | Logical OR | True if at least one operand is true | |
! |
Logical NOT | Reverses the boolean value | !x |
false |