0% found this document useful (0 votes)
10 views

Week 2

jkh

Uploaded by

Firdous Chandio
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Week 2

jkh

Uploaded by

Firdous Chandio
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

VISUAL PROGRAMMING

Engr. Anees Ahmed Soomro


Assistant Professor
CS QUEST Nawabshah

https://anees-soomro.neocities.org
OOP CONCEPTS

1) Namespaces , Passing arguments by reference or


value
2) Returning more than one value
3) OOP – access modifiers, properties, constructors
4) OOP- inheritance
Type
Predefined types
Size Range BCL Name Signed Literal Suffix

sbyte 8 bits -128 to 127 System.SByte Yes

byte 8 bits 0 to 255 System.Byte No

short 16 bits -32,768 to 32,767 System.Int16 Yes

ushort 16 bits 0 to 65,535 System.UInt16 No

int 32 bits -2,147,483,648 to System.Int32 Yes


2,147,483,647
uint 32 bits 0 to 4,294,967,295 System.UInt32 No U or u

long 64 bits -9.2e18 to 9.2e18 System.Int64 Yes L or l

ulong 64 bits 18.4e18 System.UInt64 No UL or ul

float 32 bits +-1.5e-45 to +-3.4e38 System.Single Yes F or f

double 64 bits +-5.0e-324 to +-1.7e308 System.Double Yes D or d

decimal 128 bits +-1.0e-28 to +-7.9e28 System.Decimal Yes M or m

char 16 bits 65536 characters System.Char

bool 8 bits true or false System.Boolean

All these types are value types


Value types vs Reference types
Value types: Reference types:

A variable contains the data A variable contains a reference to


directly. the data.

Examples: Examples:
all primitive types from last slide strings, arrays, objects
and structs

decimal x = 8; string a = "abc";


decimal y = string b = "abracadabra";
9; a = b; // only a reference is copied
x = y; // 16 // (typically 4-8 bytes)
bytes of data
Declarations
int myInteger;
myInteger = 1;
int yourTnteger =
0;

char x;
x = '\u0020'; //
char y = 'c'; blank

float height1;
height1 = 1.443F;
float height2 =
float.Parse("1.22
2");

string s;
s = "def";
string t =
"abc";

int[]
values;
int count
values= =more.Length; // will be 3
new int[] {
3, 2, 7, 18
};
Conditions
if (more.Length == if (<boolean>)
14) {
{ evenmore[0] += ...
22; }
}
if (more.Length < 10) { evenmore[0] +=
22;
} else {
evenmore[2] = -17;
}

if (more.Length < 10) { evenmore[0] +=


22;
} else if(more.Length > 102) { evenmore[1] = 8;
} else {
System.Console.WriteLine("why?");
}
Loops
do
{
a = int.Parse(System.Console.ReadLine());
}
while (a != 0);

while (a < 10)


{
System.Console.WriteLine("Here is your integer: {0}\n", a);
a++;
}

for (a = 0; a < 10; a++)


{
System.Console.WriteLine("Counting...\n");
}

foreach(int x in values)
{ if(x > currentMax){
currentMax = x;
}
}
Operators
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
+, -, *, / Arithmetic operators
% Rest of integer division (Remainder)
<, <=, ==, !=, >=, > Comparing operators
++x, x++, --i, i-- Pre- and post-incrementing / decrementing

Operator Meaning
|, &, ^ Binary OR, AND, XOR
<< Binary leftshift
>> Binary rightshift
Methods (functions)
public int computeMax(int[] values)
{
int currentMax = values[0];

foreach(int x in values){ if(x > currentMax){


currentMax = x;
}
}
return currentMax;
}
Objects
Everything in C# is in a
class. Nothing exists without
a class.

A class is a template for an


object.
An object has fields (data)
and methods (functions).

Recall HelloWorld:

using System;
class HelloWorld
{
static void
Main()
{
Console.W
riteLine(
"Hello
world!");
}
Objects
class Employee
{
private string FirstName; 2 fields
private string LastName;

public string GetName() 1 method


{
return string.Concat(FirstName, " ",
LastName);
} }

You might also like