Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

Emerging Technologies (IT-3302)

Week 03

Usman Akbar
usman.akbar@superior.edu.pk
FB Group - SuperiorUniversity2016
Lecture Content

 Last lecture review


 C# - if Statement & if- else if
 C# - Nested if Statements
 C# - Switch Statement
 Tasks & Questions
 References

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 2


Last Lecture Review

An operator is a symbol that tells the compiler to perform specific


mathematical or logical manipulations. C# has rich set of built-in
operators and provides the following type of operators

 Arithmetic Operators
 + - * / % ++ --

 Relational Operators
 == != > < >= <=

 Logical Operators
 && || !
 Assignment Operators
 = += -= *= /=

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 3


C# - if Statement

 An if statement consists of a boolean expression followed by one or


more statements.

if(boolean_expression)
{
/* statement(s) will execute if the boolean expression is
true */
}

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 4


Example
using System;
namespace DecisionMaking {
class Program {
static void Main(string[] args) {
/* local variable definition */
int a = 10;
/* check the boolean condition using if statement
*/
if (a < 20) {
/* if condition is true then print the following */
Console.WriteLine("a is less than 20");
}
Console.WriteLine("value of a is : {0}", a);
Console.ReadLine(); } }
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 5
C# if...else if (if-then-else if) Statement

if (boolean-expression-1)
{
// statements executed if boolean-expression-1 is
true
}
else if (boolean-expression-2)
{
// statements executed if boolean-expression-2 is
true
}
else if (boolean-expression-3)
{
// statements executed if boolean-expression-3 is
true
}

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 6


C# - Nested if Statements

if (boolean-expression-1)
{
// statements executed if boolean-expression-1 is true
??
if (boolean-expression-2)
{
// statements executed if boolean-expression-2 is
true
}
}

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 7


Class Task

Write Console C# Program which can

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 8


C# - Switch Statement

Syntax A switch statement allows a variable to be


switch(expression) { tested for equality against a list of values.
case expression : Each value is called a case, and the
statement(s); variable being switched on is checked for
break; /* optional */ each switch case.
case expression :
statement(s);
break; /* optional */
/* you can have any number of case
statements */
default : /* Optional */
statement(s);
}
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 9
Grades : Example

char grade = 'B';

switch (grade) {
case 'A':
Console.WriteLine("Excellent!");
break;
case 'B':
case 'C':
Console.WriteLine("Well done");
break;
case 'D':
Console.WriteLine("You passed");
break;
case 'F':
Console.WriteLine("Better try again");
break;
default:
Console.WriteLine("Invalid grade");
break;
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 10
There are following assignment operators supported by C#

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 11


Question

Questions….?
References

 C# 6 for Programmers ( Chapter 03 )


 https://www.tutorialspoint.com/csharp
 https://www.visualstudio.com

Social Community Help ….!


 https://code.msdn.microsoft.com/
 https://www.codeproject.com/
 http://stackoverflow.com/

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 13

You might also like