VISUAL PROGRAMMING
Engr. Anees Ahmed Soomro
Assistant Professor
CS QUEST Nawabshah
[Link]
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 [Link] Yes
byte 8 bits 0 to 255 [Link] 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 [Link] Yes F or f
double 64 bits +-5.0e-324 to +-1.7e308 [Link] Yes D or d
decimal 128 bits +-1.0e-28 to +-7.9e28 [Link] Yes M or m
char 16 bits 65536 characters [Link]
bool 8 bits true or false [Link]
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 =
[Link]("1.22
2");
string s;
s = "def";
string t =
"abc";
int[]
values;
int count
values= =[Link]; // will be 3
new int[] {
3, 2, 7, 18
};
Conditions
if ([Link] == if (<boolean>)
14) {
{ evenmore[0] += ...
22; }
}
if ([Link] < 10) { evenmore[0] +=
22;
} else {
evenmore[2] = -17;
}
if ([Link] < 10) { evenmore[0] +=
22;
} else if([Link] > 102) { evenmore[1] = 8;
} else {
[Link]("why?");
}
Loops
do
{
a = [Link]([Link]());
}
while (a != 0);
while (a < 10)
{
[Link]("Here is your integer: {0}\n", a);
a++;
}
for (a = 0; a < 10; a++)
{
[Link]("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 [Link](FirstName, " ",
LastName);
} }