Course Content
C# Tutorial
About Lesson

Arithmetic, Relational, Logical, and Assignment operators

Arithmetic operators in C# perform basic mathematical operations such as addition, subtraction, multiplication, division, and modulus. These operators allow manipulation of numerical values within C# programs, enhancing their functionality and flexibility.

Addition Operator (+)

The addition operator, denoted by the symbol ‘+’, combines two values to produce their sum. For instance:

int a = 10;
int b = 20;
int sum = a + b; // sum will be 30

Subtraction Operator (-)

The subtraction operator, represented by the symbol ‘-‘, subtracts the second operand from the first one:

int a = 50;
int b = 30;
int difference = a - b; // difference will be 20

Multiplication Operator (*)

The multiplication operator ‘*’, multiplies two values together:

int a = 5;
int b = 8;
int product = a * b; // product will be 40

Division Operator (/)

The division operator ‘/’, divides one value by another:

int a = 50;
int b = 10;
int quotient = a / b; // quotient will be 5

Modulus Operator (%)

The modulus operator ‘%’, returns the remainder of a division operation:

int a = 17;
int b = 5;
int remainder = a % b; // remainder will be 2

Understanding Relational Operators in C#

Relational operators in C# are used to determine the relationship between two operands, producing a boolean result (true or false) based on the comparison.

Greater Than (>)

int a = 10;
int b = 5;
bool result = a > b; // result will be true

Less Than (<)

int a = 8;
int b = 12;
bool result = a < b; // result will be true

Greater Than or Equal To (>=)

int a = 15;
int b = 15;
bool result = a >= b; // result will be true

Less Than or Equal To (<=)

int a = 20;
int b = 20;
bool result = a <= b; // result will be true

Logical Operators in C#

Logical operators in C# are used to perform logical operations between boolean values.

Logical AND (&&)

bool a = true;
bool b = false;
bool result = a && b; // result will be false

Logical OR (||)

bool a = true;
bool b = false;
bool result = a || b; // result will be true

Logical NOT (!)

bool a = true;
bool result = !a; // result will be false

Assignment Operators in C#

Assignment operators in C# are used to assign values to variables.

Assignment Operator (=)

int x;
x = 10; // x is assigned the value 10

Compound Assignment Operators (+=, -=, *=, /=, %=)

int y = 5;
y += 3; // Equivalent to y = y + 3 (y will be 8)

Understanding these fundamental operators in C# is crucial for developing efficient and functional programs. Incorporate these operators wisely to manipulate data and control program flow effectively