fourth class material (Operators)
There are five types of operator in c sharp.1. Arithmatic operator
2. Arithmatic assignment operator
3. Unary operator
4. Comparison Operator
5. Logical Operator
1. Arithmatic operator : +, - , * , / , %
2. Arithmatic assignment operator : +=, -= , *= , /= , %=
3. Unary Operator : ++, --
4. Comparison Operator : < , > , <=, >=, ==, !=
5. Logical Operator : &&, ||, !
1..Arithmatic operator :
a=8, b=4, c;
c=a+b;
output is 12
a=2, b=4, c;
c=a-b;
output is 4
2. Arithmatic assignment operator
a=4;
b=6;
a+=b;
output is 10 and contain value in 'a'.
here a+=b mean a=a+b;
a-=b;
output is -2
3. Unary Operator
a=2;
b=4;
a++;
output is 3 and contain value in 'a'
here a++ mean a+1.
++ mean increament by 1;
-- mean decreament by 1;
here is two type of unary operator first one is pre and 2nd one is post.
if we use unary operator in bafore value called pre and use after value called post.
a++ mean post increament.
++a mean pre increament.
a=++b;
here value of
a is a=5 and b=5;
a=b++;
than value of a 4 but b is 5;
a=--b;
here value of a is 3 and b= 3
a=b--;
value of a is 4 but b is 3.
4. Comparison Operator
comparison operator always checks expression and it use on if else condition
like if you have to compare 2 differ number which is greater.
Like This
using System;
class Compare
{
public static void Main()
{
int a=4, b=5;
if(a>b)
{
Console.WriteLine("a is greter");
}
else
{
Console.WriteLine("b is greter");
}
}
}
5. Logical Operator
&&, ||, !
check more dan one condition
if you have to compare 3 numbers which is greater
In && both condition should be true than return true else false.
In || any one condition should be true than it will return true else false.
In ! both condition should be false than it will return true else false.
using System;
class Compare
{
public static void Main()
{
int a=8, b=5, c=6;
if((a>b)&&(a>c))
{
Console.WriteLine("a is greter");
}
else if((b>a)&&(b>c))
{
Console.WriteLine("b is greter");
}
else
{
Console.WriteLine("c is greter");
}
}
}
Thanks To Support By : Hamara Sem
No comments:
Post a Comment