|
Post by Admin on May 29, 2014 10:47:11 GMT -5
Assignment Operator = Arithmetic Operators like +,-,*,/,% Comparison Operators like ==, !=,>, >=, <, <= Conditional Operators like &&, || && means "and". || means "or" Ternary Operator ?: Null Coalescing Operator ??
Sample Code:
using System;
class Program { static void Main() { int Numerator = 10; int Denominator = 2; int Result = Numerator / Denominator;
Console.WriteLine("Result = {0}", Result); } }
using System;
class Program { static void Main() { int Number = 10; int AnotherNumber = 20; // Number is not equal 10 if (Number != 10 && AnotherNumber == 20) { Console.WriteLine("Hello"); } } }
Program without ternary Operator
using System;
class Program { static void Main() { int Number = 10;
bool IsNumber10;
if (Number == 10) { IsNumber10 = true; } else { IsNumber10 = false; }
Console.WriteLine("Number == 10 is {0}", IsNumber10); } }
Same program with ternary Operator
using System; class Program { static void Main() { int Number = 10;
bool IsNumber10 = Number == 10 ? true : false; Console.WriteLine("i == 10 is {0}", IsNumber10); } }
|
|