Advertisement
// C# - Example of < relational operator
using System;
class A
{
public static void Main()
{
//Local variables
int a = 5, b =10, c = 100;
char ch1 = 'a', ch2 = 'b';
float f1 = 100.5f, f2 = 100.4f;
double d = 100.001;
//comparing an int to an int
if(a < b)
Console.WriteLine("{0} is less than {1}", a , b);
//comparing a character with a character
if(ch1 < ch2)
Console.WriteLine("{0} is less than {1}", ch1, ch2);
//comparing an int with ASCII value of a character
if(c < 'z')
Console.WriteLine("{0} is less than z", c);
//comparing a float with float
if(f1 < f2)
Console.WriteLine("{0} is less than {1}", f1, f2);
//comparing an int with a double
if(c < d)
Console.WriteLine("{0} is less than {1}",c, d);
}
}
5 is less than 10
a is less than b
100 is less than z
100 is less than 100.001
// C# - Example of > relational operator
using System;
class A
{
public static void Main()
{
//Local variables
int a = 10, b =10, c = 200;
char ch1 = 'a', ch2 = 'b';
float f1 = 100.5f, f2 = 100.4999f;
double d = 100.001;
//comparing an int to an int
if(a > b)
Console.WriteLine("{0} is greater than {1}", a , b);
//comparing a character with a character
if(ch1 > ch2)
Console.WriteLine("{0} is greater than {1}", ch1, ch2);
//comparing an int with ASCII value of a character
if(c > 'z')
Console.WriteLine("{0} is greater than z", c);
//comparing a float with float
if(f1 > f2)
Console.WriteLine("{0} is greater than {1}", f1, f2);
//comparing an int with a double
if(c > d)
Console.WriteLine("{0} is greater than {1}",c, d);
}
}
200 is greater than z
100.5 is greater than 100.4999
200 is greater than 100.001
Advertisement
// C# - Example of <= relational operator
using System;
class A
{
public static void Main()
{
//Local variables
int a = 5, b = 6, c = 10;
char ch1 = 'a', ch2 = 'b';
float f1 = 6.0f, f2 = 20.6f;
double d1 = 10.5, d2 = 20.5;
//comparing a character with another character
if(ch1 <= ch2)
Console.WriteLine("{0} is less than or equal to {1}", a, b);
//comparing a character's ASCII value with int
if(ch1 <= 100)
Console.WriteLine("{0} is less than or equal to 100", ch1, 100);
//comparing a character with another character
if(ch2 <= 'b')
Console.WriteLine("{0} is less than equal to {1}", ch2, 'b');
//comparing an double value with a float
if(d2 <= f2)
Console.WriteLine("{0} is less than or equal to {1}", d2, f2);
//comparing a double with a double
if(d1 <= 10.5)
Console.WriteLine("{0} is less than or equal to {1}", d1, 10.5);
//comparing an int to int
if(a <= b)
Console.WriteLine("{0} is less than or equal to {1}", a, b);
//comparing an int with a float
if(b <= 7.5f)
Console.WriteLine("{0} is less than or equal to {1}", b, 7.5f);
//comparing an int with a float
if(b <= f1)
Console.WriteLine("{0} is less than or equal to {1}", b, f1);
//comparing an int with a double
if(c <= d1)
Console.WriteLine("{0} is less than or equal to {1}", c, d1);
}
}
5 is less than or equal to 6
a is less than or equal to 100
b is less than equal to b
20.5 is less than or equal to 20.6
10.5 is less than or equal to 10.5
5 is less than or equal to 6
6 is less than or equal to 7.5
6 is less than or equal to 6
10 is less than or equal to 10.5
// C# - Example of >= relational operator
using System;
class A
{
public static void Main()
{
//Local variables
int a = 5, b = 6, c = 10;
char ch1 = 'x', ch2 = 'e';
float f1 = 6.0f, f2 = 20.6f;
double d1 = 10.5, d2 = 30.5;
//comparing a character with another character
if(ch1 >= ch2)
Console.WriteLine("{0} is greater than or equal to {1}", ch1, ch2);
//comparing a character's ASCII value with int
if(ch1 >= 10)
Console.WriteLine("{0} is greater than or equal to 10", ch1, 10);
//comparing a character with another character
if(ch2 >= 'b')
Console.WriteLine("{0} is greater than equal to {1}", ch2, 'b');
//comparing an double value with a float
if(d2 >= f2)
Console.WriteLine("{0} is greater than or equal to {1}", d2, f2);
//comparong a double with a double
if(d1 >= 10.5)
Console.WriteLine("{0} is greater than or equal to {1}", d1, 10.5);
//comparing an int to int
if(a >= b)
Console.WriteLine("{0} is greater than or equal to {1}", a, b);
//comparing an int with a float
if(b >= 3.5f)
Console.WriteLine("{0} is greater than or equal to {1}", b, 3.5f);
//comparing an int with a float
if(b >= f1)
Console.WriteLine("{0} is greater than or equal to {1}", b, f1);
//comparing an int with a double
if(c >= d1)
Console.WriteLine("{0} is greater than or equal to {1}", c, d1);
}
}
x is greater than or equal to e
x is greater than or equal to 10
e is greater than equal to b
30.5 is greater than or equal to 20.6
10.5 is greater than or equal to 10.5
6 is greater than or equal to 3.5
6 is greater than or equal to 6
// C# - Example of == relational operator
using System;
class A
{
public static void Main()
{
//Local variables
int a = 100, b = 5;
char ch1 = 'z', ch2 = 'a';
float f2 = 99.99f;
double d1 = 50.5, d2 = 99.9999;
//comparing a character with another character
if(ch1 == 'z')
Console.WriteLine("{0} is greater than or equal to {1}", ch1, 'z');
//comparing a double value with a double
if(d1 == 50.5)
Console.WriteLine("{0} is greater than or equal to 50.5", d1, 50.5);
//comparing an int with another double
if(a == 100.001)
Console.WriteLine("{0} is greater than equal to 100.001", a, 100.001);
//comparing an double value with a float
if(d2 == f2)
Console.WriteLine("{0} is greater than or equal to {1}", d2, f2);
//comparong a double with a double
if(d1 == 10.5)
Console.WriteLine("{0} is greater than or equal to {1}", d1, 10.5);
//comparing an int to float
if(b == 4.999f)
Console.WriteLine("{0} is greater than or equal to {1}", b, 4.999f);
//comparing an int with a double
if(ch2 == 97)
Console.WriteLine("{0} is greater than or equal to {1}", ch2, 97);
}
}
z is greater than or equal to z
50.5 is greater than or equal to 50.5
a is greater than or equal to 97
// C# - Example of != relational operator
using System;
class A
{
public static void Main()
{
//Local variables
int a = 100, b = 5;
char ch1 = 'z', ch2 = 'a';
float f2 = 99.999f;
double d1 = 50.5, d2 = 99.9999;
//comparing a character with another character
if(ch1 != 'z')
Console.WriteLine("{0} is not equal to {1}", ch1, 'z');
//comparing a character with another character
if(ch1 != ch2)
Console.WriteLine("{0} is not equal to {1}", ch1, ch2);
//comparing a double value with a double
if(d1 != 50.4)
Console.WriteLine("{0} is not equal to 50.4", d1, 50.4);
//comparing an int with another double
if(a != 100.001)
Console.WriteLine("{0} is greater than equal to 100.001", a, 100.001);
//comparing an double value with a float
if(d2 != f2)
Console.WriteLine("{0} is not equal to {1}", d2, f2);
//comparong a double with a double
if(d1 != 10.5)
Console.WriteLine("{0} is not equal to {1}", d1, 10.5);
//comparing an int to float
if(b != 4.999f)
Console.WriteLine("{0} is not equal to {1}", b, 4.999f);
//comparing an int with a double
if(ch2 != 97)
Console.WriteLine("{0} is not equal to {1}", ch2, 97);
}
}
z is not equal to a
50.5 is not equal to 50.4
100 is greater than equal to 100.001
99.9999 is not equal to 99.999
50.5 is not equal to 10.5
5 is not equal to 4.999
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement