SlideShare a Scribd company logo
1 of 50
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Value Types & Reference Types
Q3M1
Dudy Fathan Ali, S.Kom (DFA)
2015
CEP - CCIT
Fakultas Teknik Universitas Indonesia
Introduction
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
o The variables in a program are allocated memory at run
time in the system.
o Variables are referred in two ways, value type and
reference type.
o Value type variables contain data, whereas reference
type variables hold the reference to the memory
location where data is stored.
Describing Memory Allocation
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
The memory allocated to variables is referred to in two ways, value
types and reference types.
- OOP C#, NIIT Courseware MMSv2.
int Num1 = 50;
int Num2 = 100;
Example :
50
Value types are also called direct
types because they contain data.
100
Num1
Num2
Memory Allocated for Value Type Variable
Describing Memory Allocation
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
The memory allocated to variables is referred to in two ways, value
types and reference types.
- OOP C#, NIIT Courseware MMSv2.
int Num1 = 50;
int Num2 = Num1;
Console.WriteLine(Num1);
Console.WriteLine(Num2);
Another Example :
50
50
Num1
Num2
Value types are also called direct
types because they contain data.
Memory Allocated for Value Type Variable
Describing Memory Allocation
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
The memory allocated to variables is referred to in two ways, value
types and reference types.
- OOP C#, NIIT Courseware MMSv2.
int Num1 = 50;
int Num2 = Num1;
Console.WriteLine(Num1);
Num1++;
Console.WriteLine(Num2);
Another Example :
Output:
50
50
incrementing Num1 will have no effect on Num2
Value types are also called direct
types because they contain data.
Memory Allocated for Value Type Variable
Describing Memory Allocation
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
class Car
{
public int Model;
public void Display_Model()
{
Console.WriteLine (Model);
}
}
class Program
{
static void Main (string[] args)
{
Car Ford = new Car ();
Ford.Model = 10;
Car Mercedes = Ford;
Ford.Display_Model();
Mercedes.Display_Model ();
}
}
Memory Allocated for Reference Type Variable
****
Ford
****
Mercedes
10
**** Output:
10
10
Describing Memory Allocation
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
class Car
{
public int Model;
public void Display_Model()
{
Console.WriteLine (Model);
}
}
class Program
{
static void Main (string[] args)
{
Car Ford = new Car ();
Ford.Model = 10;
Car Mercedes = Ford;
Ford.Display_Model();
Ford.Model++;
Mercedes.Display_Model ();
}
}
Memory Allocated for Reference Type Variable
****
Ford
****
Mercedes
10
****
11
Incrementing Form.Model will changing the value
of Mercedes.Model.
Enumeration
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Enumeration is a value type data type, it allows you to assign symbolic
names to integral constants.
- OOP C#, NIIT Courseware MMSv2.
enum Days { Sat, Sun, Mon, Tue, Wed, Thu, Fri };
To declare an enumeration type called Days, where the values are restricted to the
symbolic names of the weekdays, use the following code:
Code :
Integral
Constant
0 1 2 3 4 5 6
Symbolic
Name
Sat Sun Mon Tue Wed Thu Fri
Representation :
Enumeration
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
class EnumTest
{
enum Days { Sat, Sun, Mon, Tue, Wed, Thu,
Fri };
static void Main(string[] args)
{
int First_Day = (int)Days.Sat;
int Last_Day = (int)Days.Fri;
Console.WriteLine(“Sat = ” + First_Day);
Console.WriteLine(“Fri = ” + Last_Day);
Console.ReadLine();
}
}
Integral
Constant
0 1 2 3 4 5 6
Symbolic
Name
Sat Sun Mon Tue Wed Thu Fri
Full Code :
Representation :
Output:
Sat = 0
Fri = 6
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
An array is a collection of values of the same data type. Array
elements are accessed using a single name and an index number
representing the position of the element within the array. Array is a
reference type data type.
Array Structure
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Declaring an Array
An array needs to be declared before it can be used in a program. You can declare
an array by using the following statement :
<data type>[] <array name>
Code Structure :
String[] DaftarNama;
Example Code :
String[] DaftarNama = new String[2];
DaftarNama[0] = “Bambang”;
DaftarNama[1] = “Suprapto”;
Initializing and Assigning Value :
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
string[] n1 = new string[5];
Data Dalam Memori :
Data Dalam Array :
i=0
Indeks di mulai
dari 0
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
string[] n1 = new string[5];
Data Dalam Memori :
Data Dalam Array :
i=0
Masuk Nilai “1”
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1
string[] n1 = new string[5];
n1[0] = “1”;
Data Dalam Memori :
i=0
a
1 a
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1
string[] n1 = new string[5];
n1[0] = “1”;
Data Dalam Memori :
i=0
a
1 a
Masuk Nilai “5”
a
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
a
b
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
Masuk Nilai “7”
a
b
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[2] = “7”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[2] = “7”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
Masuk Nilai “3”
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7 3
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[2] = “7”;
n1[3] = “3”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
i=3
d
d
3 d
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7 3
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[2] = “7”;
n1[3] = “3”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
i=3
d
d
3 d
Masuk Nilai “9”
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7 3 9
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[2] = “7”;
n1[3] = “3”;
n1[4] = “9”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
i=3
d
d
3 d
e
e
e9
i=4
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7 3 9
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[3] = “7”;
n1[4] = “3”;
n1[5] = “9”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
i=3
d
d
3 d
e
e
e9
i=4
Bisa diisi lagi?
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
1 5 7 3 9
string[] n1 = new string[5];
n1[0] = “1”;
n1[1] = “5”;
n1[3] = “7”;
n1[4] = “3”;
n1[5] = “9”;
Data Dalam Memori :
i=0
a
1 a
i=1
b
5 b
c
i=2
7 c
a
b
c
i=3
d
d
3 d
e
e
e9
i=4
Tidak! Karena
Array PENUH.
Assigning Value
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
x = 5
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
x = 5
i=0
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
x = 5
i=0 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
x = 5
n[0] = 1i=0 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
x = 5
n[0] = 1 Tampil “1”i=0 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
n[0] = 1 Tampil “1” i = i+ 1i=0
x = 5
i < x
Y i yang baru = 1
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
x = 5
i=1 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
x = 5
n[1] = 5i=1 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
x = 5
n[1] = 5 Tampil “5”i=1 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
n[1] = 5 Tampil “5” i = i+ 1i=1
x = 5
i < x
Y i yang baru = 2
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
x = 5
i=2 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
x = 5
n[2] = 3i=2 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
x = 5
n[2] = 3 Tampil “3”i=2 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
n[2] = 3 Tampil “3” i = i+ 1i=2
x = 5
i < x
Y i yang baru = 3
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
x = 5
i=3 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
x = 5
n[3] = 8i=3 i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
n[3] = 8 Tampil “8”i=3
x = 5
i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
n[4] = 4 Tampil “4” i = i+ 1i=3
x = 5
i < x
Y i yang baru = 4
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
i=4
x = 5
i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
n[4] = 4i=4
x = 5
i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
4
n[4] = 4 Tampil “4”i=4
x = 5
i < x
Y
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
4
n[4] = 4 Tampil “4” i = i+ 1i=4
x = 5
i < x
Y i yang baru = 5
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
4
i=5
x = 5
i < x
N
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Display Array Value
string[] n1 = new string[5]
n1[0] = 1;
n1[1] = 5;
n1[2] = 3;
n1[3] = 8;
n1[4] = 4;
int x,i;
x = n1.length();
i = 0;
for(i=0;i<x;i++)
{
Console.WriteLine(n1[i]);
}
Console.ReadLine();
Data array
int x,i
i++
Y
N
next
command
x = n1.length
i = 0
i < x
Tampil nilai “i”
1 5 3 8 4
i=0 i=1 i=2 i=3 i=4
Tampil Di Layar :
1
5
3
8
4
Data telah tampil semua
Array
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Latihan Mandiri
1. Buatlah array untuk menyimpan sejumlah nama siswa (jumlah
siswa berdasarkan inputan user)
2. Buatlah 2 array untuk menyimpan angka ganjil dan angka genap
dari 0 – 20 dan
3. Jumlahkanlah isi dari array ganjil dan array genap
4. Jumlahkanlah array ganjil dan genap dengan index yang sama
kemudian masukkan hasil penjumlahannya ke dalam array yang
baru
5. Hasil dari ke empat latihan di atas harus bisa ditampilkan
Q3M1 – OOP C# Dudy Fathan Ali S.Kom
Thank You!
Dudy Fathan Ali S.Kom
dudy.fathan@eng.ui.ac.id
Credits array content by : Yaddarabullah S.Kom M.Kom

More Related Content

What's hot

Array within a class
Array within a classArray within a class
Array within a classAAKASH KUMAR
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Anton Kolotaev
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project FileDeyvessh kumar
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Sheik Uduman Ali
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
20170317 functional programming in julia
20170317 functional programming in julia20170317 functional programming in julia
20170317 functional programming in julia岳華 杜
 
20170714 concurrency in julia
20170714 concurrency in julia20170714 concurrency in julia
20170714 concurrency in julia岳華 杜
 
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...Mumbai B.Sc.IT Study
 
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Peng Cheng
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Kamlesh Makvana
 

What's hot (20)

Array within a class
Array within a classArray within a class
Array within a class
 
E7
E7E7
E7
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
 
Templates
TemplatesTemplates
Templates
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Advanced C - Part 3
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
20170317 functional programming in julia
20170317 functional programming in julia20170317 functional programming in julia
20170317 functional programming in julia
 
Cs 2003
Cs 2003Cs 2003
Cs 2003
 
Network security CS6
Network security   CS6Network security   CS6
Network security CS6
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
20170714 concurrency in julia
20170714 concurrency in julia20170714 concurrency in julia
20170714 concurrency in julia
 
Ch8a
Ch8aCh8a
Ch8a
 
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
 
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 

Viewers also liked

Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - InheritanceDudy Ali
 
Object Oriented Programming - File Input & Output
Object Oriented Programming - File Input & OutputObject Oriented Programming - File Input & Output
Object Oriented Programming - File Input & OutputDudy Ali
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseJava CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseDudy Ali
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsObject Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsDudy Ali
 
Database Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL ServerDatabase Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL ServerDudy Ali
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overridingPinky Anaya
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#foreverredpb
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVADudy Ali
 
Csc153 chapter 07
Csc153 chapter 07Csc153 chapter 07
Csc153 chapter 07PCC
 
Information System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses KontrolInformation System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses KontrolDudy Ali
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationObject Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationDudy Ali
 
Information System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses KontrolInformation System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses KontrolDudy Ali
 
Information System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan EkstranetInformation System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan EkstranetDudy Ali
 
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen KeamananInformation System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen KeamananDudy Ali
 
Information System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen KeamananInformation System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen KeamananDudy Ali
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi PenjualanDiagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi PenjualanRicky Kusriana Subagja
 

Viewers also liked (20)

Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - Inheritance
 
Object Oriented Programming - File Input & Output
Object Oriented Programming - File Input & OutputObject Oriented Programming - File Input & Output
Object Oriented Programming - File Input & Output
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseJava CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server Database
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsObject Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & Destructors
 
Database Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL ServerDatabase Introduction - Akses Data dengan SQL Server
Database Introduction - Akses Data dengan SQL Server
 
Csharp_Chap03
Csharp_Chap03Csharp_Chap03
Csharp_Chap03
 
Lo2
Lo2Lo2
Lo2
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVA
 
Value Types
Value TypesValue Types
Value Types
 
Csc153 chapter 07
Csc153 chapter 07Csc153 chapter 07
Csc153 chapter 07
 
Information System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses KontrolInformation System Security - Akuntabilitas dan Akses Kontrol
Information System Security - Akuntabilitas dan Akses Kontrol
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationObject Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & Encapsulation
 
Information System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses KontrolInformation System Security - Teknik Akses Kontrol
Information System Security - Teknik Akses Kontrol
 
Information System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan EkstranetInformation System Security - Komponen Intranet dan Ekstranet
Information System Security - Komponen Intranet dan Ekstranet
 
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen KeamananInformation System Security - Prinsip Manajemen Keamanan
Information System Security - Prinsip Manajemen Keamanan
 
Information System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen KeamananInformation System Security - Konsep Manajemen Keamanan
Information System Security - Konsep Manajemen Keamanan
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi PenjualanDiagram Konteks dan DFD Sistem Informasi Penjualan
Diagram Konteks dan DFD Sistem Informasi Penjualan
 

Similar to Object Oriented Programming - Value Types & Reference Types

Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxarjurakibulhasanrrr7
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 DsQundeel
 
Data Structure
Data StructureData Structure
Data Structuresheraz1
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 DsQundeel
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
Data structure and algorithm notes
Data structure and algorithm notesData structure and algorithm notes
Data structure and algorithm notessuman khadka
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notesGOKULKANNANMMECLECTC
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 

Similar to Object Oriented Programming - Value Types & Reference Types (20)

Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Data Structure
Data StructureData Structure
Data Structure
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Ansi c
Ansi cAnsi c
Ansi c
 
Arrays
ArraysArrays
Arrays
 
DSA 103 Object Oriented Programming :: Week 5
DSA 103 Object Oriented Programming :: Week 5DSA 103 Object Oriented Programming :: Week 5
DSA 103 Object Oriented Programming :: Week 5
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Review version 4
Review version 4Review version 4
Review version 4
 
Data structure and algorithm notes
Data structure and algorithm notesData structure and algorithm notes
Data structure and algorithm notes
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
C arrays
C arraysC arrays
C arrays
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Unit 3
Unit 3 Unit 3
Unit 3
 

More from Dudy Ali

Understanding COM+
Understanding COM+Understanding COM+
Understanding COM+Dudy Ali
 
Distributed Application Development (Introduction)
Distributed Application Development (Introduction)Distributed Application Development (Introduction)
Distributed Application Development (Introduction)Dudy Ali
 
Review Materi ASP.NET
Review Materi ASP.NETReview Materi ASP.NET
Review Materi ASP.NETDudy Ali
 
XML Schema Part 2
XML Schema Part 2XML Schema Part 2
XML Schema Part 2Dudy Ali
 
XML Schema Part 1
XML Schema Part 1XML Schema Part 1
XML Schema Part 1Dudy Ali
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML DocumentDudy Ali
 
Pengantar XML
Pengantar XMLPengantar XML
Pengantar XMLDudy Ali
 
Pengantar XML DOM
Pengantar XML DOMPengantar XML DOM
Pengantar XML DOMDudy Ali
 
Pengantar ADO.NET
Pengantar ADO.NETPengantar ADO.NET
Pengantar ADO.NETDudy Ali
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBCDudy Ali
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTDudy Ali
 
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma PengurutanAlgorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma PengurutanDudy Ali
 
Algorithm & Data Structure - Pengantar
Algorithm & Data Structure - PengantarAlgorithm & Data Structure - Pengantar
Algorithm & Data Structure - PengantarDudy Ali
 
Web Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman WebWeb Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman WebDudy Ali
 
Web Programming Syaria - PHP
Web Programming Syaria - PHPWeb Programming Syaria - PHP
Web Programming Syaria - PHPDudy Ali
 
Software Project Management - Project Management Knowledge
Software Project Management - Project Management KnowledgeSoftware Project Management - Project Management Knowledge
Software Project Management - Project Management KnowledgeDudy Ali
 
Software Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen ProyekSoftware Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen ProyekDudy Ali
 
Software Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen ProyekSoftware Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen ProyekDudy Ali
 
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)Dudy Ali
 
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan SistemSystem Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan SistemDudy Ali
 

More from Dudy Ali (20)

Understanding COM+
Understanding COM+Understanding COM+
Understanding COM+
 
Distributed Application Development (Introduction)
Distributed Application Development (Introduction)Distributed Application Development (Introduction)
Distributed Application Development (Introduction)
 
Review Materi ASP.NET
Review Materi ASP.NETReview Materi ASP.NET
Review Materi ASP.NET
 
XML Schema Part 2
XML Schema Part 2XML Schema Part 2
XML Schema Part 2
 
XML Schema Part 1
XML Schema Part 1XML Schema Part 1
XML Schema Part 1
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
Pengantar XML
Pengantar XMLPengantar XML
Pengantar XML
 
Pengantar XML DOM
Pengantar XML DOMPengantar XML DOM
Pengantar XML DOM
 
Pengantar ADO.NET
Pengantar ADO.NETPengantar ADO.NET
Pengantar ADO.NET
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLT
 
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma PengurutanAlgorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Algoritma Pengurutan
 
Algorithm & Data Structure - Pengantar
Algorithm & Data Structure - PengantarAlgorithm & Data Structure - Pengantar
Algorithm & Data Structure - Pengantar
 
Web Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman WebWeb Programming Syaria - Pengenalan Halaman Web
Web Programming Syaria - Pengenalan Halaman Web
 
Web Programming Syaria - PHP
Web Programming Syaria - PHPWeb Programming Syaria - PHP
Web Programming Syaria - PHP
 
Software Project Management - Project Management Knowledge
Software Project Management - Project Management KnowledgeSoftware Project Management - Project Management Knowledge
Software Project Management - Project Management Knowledge
 
Software Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen ProyekSoftware Project Management - Proses Manajemen Proyek
Software Project Management - Proses Manajemen Proyek
 
Software Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen ProyekSoftware Project Management - Pengenalan Manajemen Proyek
Software Project Management - Pengenalan Manajemen Proyek
 
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Unified Modeling Language (UML)
 
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan SistemSystem Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Object Oriented Programming - Value Types & Reference Types

  • 1. Q3M1 – OOP C# Dudy Fathan Ali S.Kom Value Types & Reference Types Q3M1 Dudy Fathan Ali, S.Kom (DFA) 2015 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2. Introduction Q3M1 – OOP C# Dudy Fathan Ali S.Kom o The variables in a program are allocated memory at run time in the system. o Variables are referred in two ways, value type and reference type. o Value type variables contain data, whereas reference type variables hold the reference to the memory location where data is stored.
  • 3. Describing Memory Allocation Q3M1 – OOP C# Dudy Fathan Ali S.Kom The memory allocated to variables is referred to in two ways, value types and reference types. - OOP C#, NIIT Courseware MMSv2. int Num1 = 50; int Num2 = 100; Example : 50 Value types are also called direct types because they contain data. 100 Num1 Num2 Memory Allocated for Value Type Variable
  • 4. Describing Memory Allocation Q3M1 – OOP C# Dudy Fathan Ali S.Kom The memory allocated to variables is referred to in two ways, value types and reference types. - OOP C#, NIIT Courseware MMSv2. int Num1 = 50; int Num2 = Num1; Console.WriteLine(Num1); Console.WriteLine(Num2); Another Example : 50 50 Num1 Num2 Value types are also called direct types because they contain data. Memory Allocated for Value Type Variable
  • 5. Describing Memory Allocation Q3M1 – OOP C# Dudy Fathan Ali S.Kom The memory allocated to variables is referred to in two ways, value types and reference types. - OOP C#, NIIT Courseware MMSv2. int Num1 = 50; int Num2 = Num1; Console.WriteLine(Num1); Num1++; Console.WriteLine(Num2); Another Example : Output: 50 50 incrementing Num1 will have no effect on Num2 Value types are also called direct types because they contain data. Memory Allocated for Value Type Variable
  • 6. Describing Memory Allocation Q3M1 – OOP C# Dudy Fathan Ali S.Kom class Car { public int Model; public void Display_Model() { Console.WriteLine (Model); } } class Program { static void Main (string[] args) { Car Ford = new Car (); Ford.Model = 10; Car Mercedes = Ford; Ford.Display_Model(); Mercedes.Display_Model (); } } Memory Allocated for Reference Type Variable **** Ford **** Mercedes 10 **** Output: 10 10
  • 7. Describing Memory Allocation Q3M1 – OOP C# Dudy Fathan Ali S.Kom class Car { public int Model; public void Display_Model() { Console.WriteLine (Model); } } class Program { static void Main (string[] args) { Car Ford = new Car (); Ford.Model = 10; Car Mercedes = Ford; Ford.Display_Model(); Ford.Model++; Mercedes.Display_Model (); } } Memory Allocated for Reference Type Variable **** Ford **** Mercedes 10 **** 11 Incrementing Form.Model will changing the value of Mercedes.Model.
  • 8. Enumeration Q3M1 – OOP C# Dudy Fathan Ali S.Kom Enumeration is a value type data type, it allows you to assign symbolic names to integral constants. - OOP C#, NIIT Courseware MMSv2. enum Days { Sat, Sun, Mon, Tue, Wed, Thu, Fri }; To declare an enumeration type called Days, where the values are restricted to the symbolic names of the weekdays, use the following code: Code : Integral Constant 0 1 2 3 4 5 6 Symbolic Name Sat Sun Mon Tue Wed Thu Fri Representation :
  • 9. Enumeration Q3M1 – OOP C# Dudy Fathan Ali S.Kom class EnumTest { enum Days { Sat, Sun, Mon, Tue, Wed, Thu, Fri }; static void Main(string[] args) { int First_Day = (int)Days.Sat; int Last_Day = (int)Days.Fri; Console.WriteLine(“Sat = ” + First_Day); Console.WriteLine(“Fri = ” + Last_Day); Console.ReadLine(); } } Integral Constant 0 1 2 3 4 5 6 Symbolic Name Sat Sun Mon Tue Wed Thu Fri Full Code : Representation : Output: Sat = 0 Fri = 6
  • 10. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom An array is a collection of values of the same data type. Array elements are accessed using a single name and an index number representing the position of the element within the array. Array is a reference type data type. Array Structure
  • 11. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Declaring an Array An array needs to be declared before it can be used in a program. You can declare an array by using the following statement : <data type>[] <array name> Code Structure : String[] DaftarNama; Example Code : String[] DaftarNama = new String[2]; DaftarNama[0] = “Bambang”; DaftarNama[1] = “Suprapto”; Initializing and Assigning Value :
  • 12. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom string[] n1 = new string[5]; Data Dalam Memori : Data Dalam Array : i=0 Indeks di mulai dari 0 Assigning Value
  • 13. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom string[] n1 = new string[5]; Data Dalam Memori : Data Dalam Array : i=0 Masuk Nilai “1” Assigning Value
  • 14. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 string[] n1 = new string[5]; n1[0] = “1”; Data Dalam Memori : i=0 a 1 a Assigning Value
  • 15. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 string[] n1 = new string[5]; n1[0] = “1”; Data Dalam Memori : i=0 a 1 a Masuk Nilai “5” a Assigning Value
  • 16. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b a b Assigning Value
  • 17. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b Masuk Nilai “7” a b Assigning Value
  • 18. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[2] = “7”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c Assigning Value
  • 19. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[2] = “7”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c Masuk Nilai “3” Assigning Value
  • 20. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 3 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[2] = “7”; n1[3] = “3”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c i=3 d d 3 d Assigning Value
  • 21. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 3 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[2] = “7”; n1[3] = “3”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c i=3 d d 3 d Masuk Nilai “9” Assigning Value
  • 22. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 3 9 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[2] = “7”; n1[3] = “3”; n1[4] = “9”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c i=3 d d 3 d e e e9 i=4 Assigning Value
  • 23. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 3 9 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[3] = “7”; n1[4] = “3”; n1[5] = “9”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c i=3 d d 3 d e e e9 i=4 Bisa diisi lagi? Assigning Value
  • 24. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom 1 5 7 3 9 string[] n1 = new string[5]; n1[0] = “1”; n1[1] = “5”; n1[3] = “7”; n1[4] = “3”; n1[5] = “9”; Data Dalam Memori : i=0 a 1 a i=1 b 5 b c i=2 7 c a b c i=3 d d 3 d e e e9 i=4 Tidak! Karena Array PENUH. Assigning Value
  • 25. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : x = 5
  • 26. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : x = 5 i=0
  • 27. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : x = 5 i=0 i < x Y
  • 28. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : x = 5 n[0] = 1i=0 i < x Y
  • 29. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 x = 5 n[0] = 1 Tampil “1”i=0 i < x Y
  • 30. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 n[0] = 1 Tampil “1” i = i+ 1i=0 x = 5 i < x Y i yang baru = 1
  • 31. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 x = 5 i=1 i < x Y
  • 32. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 x = 5 n[1] = 5i=1 i < x Y
  • 33. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 x = 5 n[1] = 5 Tampil “5”i=1 i < x Y
  • 34. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 n[1] = 5 Tampil “5” i = i+ 1i=1 x = 5 i < x Y i yang baru = 2
  • 35. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 x = 5 i=2 i < x Y
  • 36. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 x = 5 n[2] = 3i=2 i < x Y
  • 37. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 x = 5 n[2] = 3 Tampil “3”i=2 i < x Y
  • 38. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 n[2] = 3 Tampil “3” i = i+ 1i=2 x = 5 i < x Y i yang baru = 3
  • 39. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 x = 5 i=3 i < x Y
  • 40. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 x = 5 n[3] = 8i=3 i < x Y
  • 41. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 n[3] = 8 Tampil “8”i=3 x = 5 i < x Y
  • 42. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 n[4] = 4 Tampil “4” i = i+ 1i=3 x = 5 i < x Y i yang baru = 4
  • 43. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 i=4 x = 5 i < x Y
  • 44. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 n[4] = 4i=4 x = 5 i < x Y
  • 45. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 4 n[4] = 4 Tampil “4”i=4 x = 5 i < x Y
  • 46. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 4 n[4] = 4 Tampil “4” i = i+ 1i=4 x = 5 i < x Y i yang baru = 5
  • 47. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 4 i=5 x = 5 i < x N
  • 48. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Display Array Value string[] n1 = new string[5] n1[0] = 1; n1[1] = 5; n1[2] = 3; n1[3] = 8; n1[4] = 4; int x,i; x = n1.length(); i = 0; for(i=0;i<x;i++) { Console.WriteLine(n1[i]); } Console.ReadLine(); Data array int x,i i++ Y N next command x = n1.length i = 0 i < x Tampil nilai “i” 1 5 3 8 4 i=0 i=1 i=2 i=3 i=4 Tampil Di Layar : 1 5 3 8 4 Data telah tampil semua
  • 49. Array Q3M1 – OOP C# Dudy Fathan Ali S.Kom Latihan Mandiri 1. Buatlah array untuk menyimpan sejumlah nama siswa (jumlah siswa berdasarkan inputan user) 2. Buatlah 2 array untuk menyimpan angka ganjil dan angka genap dari 0 – 20 dan 3. Jumlahkanlah isi dari array ganjil dan array genap 4. Jumlahkanlah array ganjil dan genap dengan index yang sama kemudian masukkan hasil penjumlahannya ke dalam array yang baru 5. Hasil dari ke empat latihan di atas harus bisa ditampilkan
  • 50. Q3M1 – OOP C# Dudy Fathan Ali S.Kom Thank You! Dudy Fathan Ali S.Kom dudy.fathan@eng.ui.ac.id Credits array content by : Yaddarabullah S.Kom M.Kom