Introduction
-
Operator ">" to compare two variable or values and see if one is bigger.
-
Operator "<" to compare two variable or values and see if one is smaller.
-
Operator "==" is use to compare two things are equal.
-
Operator "!=" is use to compare two things are not equal.
-
You can combine individual tests into one long test using the && operator for
AND.
-
You can combine individual tests into one long test using the || operator
for OR.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
condiction_operator
{
class
Program
{
static
void Main(string[]
args)
{
int a = 10;
int b = 15;
int c = 10;
if (a > b)
//greater then operator
{
Console.WriteLine("a
is greater then b");
}
else
{
Console.WriteLine("a
is less then to b");
}
if (a < b)
// less then operator
{
Console.WriteLine("a
is less then to b");
}
else
{
Console.WriteLine("a
is greater then to a");
}
if (a == c)
// equal operator compare two values
{
Console.WriteLine("a
is equal to c");
}
else
{
Console.WriteLine("a
is not equal to c");
}
if (a != c)
// not equal operator compare two
values
{
Console.WriteLine("a
is not equal to c");
}
else
{
Console.WriteLine("a
is equal to c");
}
if (a > b && a > c)
// greater then operator and AND
operator compare more then two values
{
Console.WriteLine("a
is greater then b and c");
}
else
{
Console.WriteLine("a
is less then b or c, or b and c");
}
if (a > b || a > c)
// greater then operator and OR
operator, compare more then two values
{
Console.WriteLine("a
is greater then b or c, or b and c ");
}
else
{
Console.WriteLine("a
is less then b or c , or b and c");
}
Console.ReadLine();
}
}
}
Output