## Algorithm

In C#, operators are symbols or keywords that perform operations on variables and values. C# supports a variety of operators, which can be categorized into several groups:

1. Arithmetic Operators:
• `+` (addition)
• `-` (subtraction)
• `*` (multiplication)
• `/` (division)
• `%` (modulus)

Example:

`csharp`
```int a = 10; int b = 3; int result = a + b; // result = 13 ```
` `
1. Comparison Operators:
• `==` (equality)
• `!=` (inequality)
• `<` (less than)
• `>` (greater than)
• `<=` (less than or equal to)
• `>=` (greater than or equal to)

Example:

`csharp`
```int x = 5; int y = 8; bool isEqual = (x == y); // isEqual = false ```
` `
1. Logical Operators:
• `&&` (logical AND)
• `||` (logical OR)
• `!` (logical NOT)

Example:

`csharp`
```bool condition1 = true; bool condition2 = false; bool result = condition1 && condition2; // result = false ```
` `
1. Assignment Operators:
• `=` (assignment)
• `+=` (add and assign)
• `-=` (subtract and assign)
• `*=` (multiply and assign)
• `/=` (divide and assign)
• `%=` (modulus and assign)

Example:

`csharp`
```int num = 10; num += 5; // num is now 15 ```
` `
1. Increment and Decrement Operators:
• `++` (increment by 1)
• `--` (decrement by 1)

Example:

`csharp`
```int count = 5; count++; // count is now 6 ```
` `
1. Bitwise Operators:
• `&` (bitwise AND)
• `|` (bitwise OR)
• `^` (bitwise XOR)
• `~` (bitwise NOT)
• `<<` (left shift)
• `>>` (right shift)

Example:

`csharp`
```int num1 = 5; // binary: 0101 int num2 = 3; // binary: 0011 int result = num1 & num2; // result = 1 (binary: 0001) ```
` `

These are some of the fundamental operators in C#. They play a crucial role in performing various operations on variables and values in your programs.

## Code Examples

### #1 Basic Assignment Operator in C# Program

```Code - C# Programming```

``````using System;

namespace Operator
{
class AssignmentOperator
{
public static void Main(string[] args)
{
int firstNumber, secondNumber;
// Assigning a constant to variable
firstNumber = 10;
Console.WriteLine("First Number = {0}", firstNumber);

// Assigning a variable to another variable
secondNumber = firstNumber;
Console.WriteLine("Second Number = {0}", secondNumber);
}
}
}``````
Copy The Code &

Output

cmd
First Number = 10
Second Number = 10

### #2 Arithmetic Operators in C# Program

```Code - C# Programming```

``````using System;

namespace Operator
{
class ArithmeticOperator
{
public static void Main(string[] args)
{
double firstNumber = 14.40, secondNumber = 4.60, result;
int num1 = 26, num2 = 4, rem;

result = firstNumber + secondNumber;
Console.WriteLine("{0} + {1} = {2}", firstNumber, secondNumber, result);

// Subtraction operator
result = firstNumber - secondNumber;
Console.WriteLine("{0} - {1} = {2}", firstNumber, secondNumber, result);

// Multiplication operator
result = firstNumber * secondNumber;
Console.WriteLine("{0} * {1} = {2}", firstNumber, secondNumber, result);

// Division operator
result = firstNumber / secondNumber;
Console.WriteLine("{0} / {1} = {2}", firstNumber, secondNumber, result);

// Modulo operator
rem = num1 % num2;
Console.WriteLine("{0} % {1} = {2}", num1, num2, rem);
}
}
}``````
Copy The Code &

Output

cmd
14.4 + 4.6 = 19
14.4 - 4.6 = 9.8
14.4 * 4.6 = 66.24
14.4 / 4.6 = 3.1304347826087
26 % 4 = 2

### #3 Relational Operators in C# Program

```Code - C# Programming```

``````using System;

namespace Operator
{
class RelationalOperator
{
public static void Main(string[] args)
{
bool result;
int firstNumber = 10, secondNumber = 20;

result = (firstNumber==secondNumber);
Console.WriteLine("{0} == {1} returns {2}",firstNumber, secondNumber, result);

result = (firstNumber > secondNumber);
Console.WriteLine("{0} > {1} returns {2}",firstNumber, secondNumber, result);

result = (firstNumber  <  secondNumber);
Console.WriteLine("{0} < {1} returns {2}",firstNumber, secondNumber, result);

result = (firstNumber >= secondNumber);
Console.WriteLine("{0} >= {1} returns {2}",firstNumber, secondNumber, result);

result = (firstNumber  < = secondNumber);
Console.WriteLine("{0} <= {1} returns {2}",firstNumber, secondNumber, result);

result = (firstNumber != secondNumber);
Console.WriteLine("{0} != {1} returns {2}",firstNumber, secondNumber, result);
}
}
}``````
Copy The Code &

Output

cmd
10 == 20 returns False
10 > 20 returns False
10 < 20 returns True
10 >= 20 returns False
10 <= 20 returns True
10 != 20 returns True

### #4 Logical Operators in C# program

```Code - C# Programming```

``````using System;

namespace Operator
{
class LogicalOperator
{
public static void Main(string[] args)
{
bool result;
int firstNumber = 10, secondNumber = 20;

// OR operator
result = (firstNumber == secondNumber) || (firstNumber > 5);
Console.WriteLine(result);

// AND operator
result = (firstNumber == secondNumber) && (firstNumber > 5);
Console.WriteLine(result);
}
}
}``````
Copy The Code &

Output

cmd
True
False

### #5 Unary Operators in C# Program

```Code - C# Programming```

``````using System;

namespace Operator
{
class UnaryOperator
{
public static void Main(string[] args)
{
int number = 10, result;
bool flag = true;

result = +number;
Console.WriteLine("+number = " + result);

result = -number;
Console.WriteLine("-number = " + result);

result = ++number;
Console.WriteLine("++number = " + result);

result = --number;
Console.WriteLine("--number = " + result);

Console.WriteLine("!flag = " + (!flag));
}
}
}``````
Copy The Code &

Output

cmd
+number = 10
-number = -10
++number = 11
--number = 10
!flag = False

### #6 Post and Pre Increment operators in C# Programming

```Code - C# Programming```

``````using System;

namespace Operator
{
class UnaryOperator
{
public static void Main(string[] args)
{
int number = 10;

Console.WriteLine((number++));
Console.WriteLine((number));

Console.WriteLine((++number));
Console.WriteLine((number));
}
}
}``````
Copy The Code &

Output

cmd
10
11
12
12

### #7 Ternary Operator in C# Programming

```Code - C# Programming```

``````using System;

namespace Operator
{
class TernaryOperator
{
public static void Main(string[] args)
{
int number = 10;
string result;

result = (number % 2 == 0)? "Even Number" : "Odd Number";
Console.WriteLine("{0} is {1}", number, result);
}
}
}``````
Copy The Code &

Output

cmd
10 is Even Number

### #8 Bitwise and Bit Shift Operator in C# Programming

```Code - C# Programming```

``````using System;

namespace Operator
{
class BitOperator
{
public static void Main(string[] args)
{
int firstNumber = 10;
int secondNumber = 20;
int result;

result = ~firstNumber;
Console.WriteLine("~{0} = {1}", firstNumber, result);

result = firstNumber & secondNumber;
Console.WriteLine("{0} & {1} = {2}", firstNumber,secondNumber, result);

result = firstNumber | secondNumber;
Console.WriteLine("{0} | {1} = {2}", firstNumber,secondNumber, result);

result = firstNumber ^ secondNumber;
Console.WriteLine("{0} ^ {1} = {2}", firstNumber,secondNumber, result);

result = firstNumber << 2;
Console.WriteLine("{0} << 2 = {1}", firstNumber, result);

result = firstNumber >> 2;
Console.WriteLine("{0} >> 2 = {1}", firstNumber, result);
}
}
}``````
Copy The Code &

Output

cmd
~10 = -11
10 & 20 = 0
10 | 20 = 30
10 ^ 20 = 30
10 << 2 = 40
10 >> 2 = 2

### #9 Compound Assignment Operator in C# Programming

```Code - C# Programming```

``````using System;

namespace Operator
{
class BitOperator
{
public static void Main(string[] args)
{
int number = 10;

number += 5;
Console.WriteLine(number);

number -= 3;
Console.WriteLine(number);

number *= 2;
Console.WriteLine(number);

number /= 3;
Console.WriteLine(number);

number %= 3;
Console.WriteLine(number);

number &= 10;
Console.WriteLine(number);

number |= 14;
Console.WriteLine(number);

number ^= 12;
Console.WriteLine(number);

number <<= 2;
Console.WriteLine(number);

number >>= 3;
Console.WriteLine(number);
}
}
}``````
Copy The Code &

Output

cmd
15
12
24
8
2
2
14
2
8
1