• Home
  • Arithmetic, Comparison, Assignment and Logical Operators

Arithmetic, Comparison, Assignment and Logical Operators

Agenda

C# Operators

Operator in C# is a symbol that is used to perform operations on variables and values. For example: +, -, *, / etc.

Important Categories of Operators:

a) Arithmetic Operators

b) Comparison Operators (Comparison operators compare two operands and returns true or false)

c) Assignment Operators

d) Logical Operators

 
int i = 50;
int j = 20;


Console.WriteLine(i+j);
Console.WriteLine(i - j);
Console.WriteLine(i * j);
Console.WriteLine(i / j);
Console.WriteLine(i % j);

Console.WriteLine(i++); //50
Console.WriteLine(i); //51
Console.WriteLine(++i); //52
Console.WriteLine(i); //52


int m = 10;
int n = 20;
Console.WriteLine(m == n);
Console.WriteLine(m != n);
Console.WriteLine(m > n);
Console.WriteLine(m >= n);
Console.WriteLine(m < n);
Console.WriteLine(m <= n);


int a = 10;
a += 5;
int b = 20;
b -= 10;
int c = 30;
c *= 5;
int d = 40;
d /= 5;
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
Console.WriteLine(d);

bool p, q;
p = true;
q = false;
Console.WriteLine(!p);
Console.WriteLine(p && q);
Console.WriteLine(p || q);


int x = 7;
Console.WriteLine(!(x > 5 && x < 10)); Console.WriteLine(x > 5 && x < 10); Console.WriteLine(x > 5 || x < 10);