4. X = 10 Y = "com")
X == 10
X != 10
X < 10
X > 10
X <= 10
X >= 10
y+"puter" == "computer"
Y == "Com"
Y != "com"
True
False
False
False
True
True
True
False
False
8. If
if (condition) statement;
(A=5, B=10)
If (A == B/2) Console.WriteLine("True");
if (condition)
statement;
If (B/2 == A)
Console.WriteLine(B+"/2 = " + A);
if (condition)
{
statement1;
statement2;
statement3;
:
}
If (A != B)
{
Console.WriteLine("A = {0}",A);
Console.WriteLine("B = {0}",B);
Console.WriteLine("{0} != {1}",A,B);
}
9. static void Main(string[] args)
{
int A = 5;
int B = 10;
if (A != B)
{
Console.WriteLine("A = {0}", A);
Console.WriteLine("B = {0}", B);
Console.WriteLine("{0} != {1}", A, B);
}
Console.ReadKey();
}
10. static void Main(string[] args)
{
char Member;
float Discount = 0f;
Console.Write("Are you Member (Y or N) : ");
Member = char.Parse(Console.ReadLine());
if ((Member == 'y') || (Member == 'Y'))
{
Discount = 0.05f;
}
Console.WriteLine("Discount is {0:p}",
Discount);
Console.ReadLine();
}
14. Nested If
if (condition)
{
if (condition)
{
statement;
}
}
(A=13, B=60)
if (A == 13)
{
if (B == 60)
{
Console.WriteLine("A = {0} and B = {1}", A, B);
}
}
15. Nested If
if (condition)
{
if (condition)
{
statement;
}
}
else
{
if (condition)
{
statement;
}
}
(A=13, B=60)
if (salary < 1650)
{
SocialSecurity = 0;
}
else
{
if (salary < 15000)
{
SocialSecurity = salary * 0.05f;
}
else
{
SocialSecurity = 15000*0.05f;
}
}
22. switch (expression)
{
case constant-expression-1:
statements;
break;
case constant-expression-2:
statements;
break;
case constant-expression-3:
statements;
break;
:
default:
statements;
break;
}
Switch…case
using System;
namespace SwitchCase
{
class Program
{
static void Main(string[] args)
{
char Operator;
int A = 5, B = 10, Total;
Operator = char.Parse(Console.ReadLine());
switch(Operator)
{
case '+': Total = A + B; break;
case '-': Total = A - B; break;
case '*': Total = A * B; break;
case '/': Total = A / B; break;
default: Total = 0; break;
}
Console.WriteLine("Answer is {0}", Total);
}
}
}