Operators
using System;
public class Operators
{
static void Main(String[] args)
{
int a = 5, b = 5, c;/* = is an assignment operator.
Other assignment operators are +=,-=,*=,/=,%=,<<=,>>=,&=,^= and |= */
c = a + b;/* + is an arithmetic operator,other arithmetic operators are
-,*,/,%,++ and -- */
Console.WriteLine("Sum of a and b= " + c);
if (c == 10)
{
Console.WriteLine("Use of relational operator");
/* == is a relational assignment operator,
other relational operators are !=,<,>,<= and >= */
}
c = a & b;/* & is a bitwise AND operator.Other bitwise operators are
|,^,~,<<,>> and >>> */
Console.WriteLine("Binary AND value of a and b= " + c);
bool b1 = true, b2 = false;
Console.WriteLine("Logical AND value of b1 and b2= " + (b1 && b2));
/* && is a logical AND operator.
Other logical operators are || and ! */
String Vehicle = "Car";
String MyVehicle = (Vehicle.Equals("Car")) ? "Car" : "Bike"; // Conditional Operator Example
Console.WriteLine("My Vehicle is " + MyVehicle);
Console.ReadLine();
}
}
Output:
Sum of a and b= 10
Use of relational operator
Binary AND value of a and b= 5
Logical AND value of b1 and b2= False
My Vehicle is Car