Week 2
Week 2
https://anees-soomro.neocities.org
OOP CONCEPTS
Examples: Examples:
all primitive types from last slide strings, arrays, objects
and structs
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;
}
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];
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;