SlideShare a Scribd company logo
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 (20)

PPTX
Array within a class
AAKASH KUMAR
 
PDF
E7
lksoo
 
PDF
Generic programming and concepts that should be in C++
Anton Kolotaev
 
PDF
Templates
Pranali Chaudhari
 
DOCX
Data Structure Project File
Deyvessh kumar
 
PPS
Let Us Learn Lambda Using C# 3.0
Sheik Uduman Ali
 
PDF
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
PDF
I PUC CS Lab_programs
Prof. Dr. K. Adisesha
 
DOC
Data structures question paper anna university
sangeethajames07
 
PPTX
20170317 functional programming in julia
岳華 杜
 
PDF
Cs 2003
Ravi Rajput
 
PDF
Network security CS6
Infinity Tech Solutions
 
PDF
Algorithms
Santosh Rajan
 
PPTX
20170714 concurrency in julia
岳華 杜
 
PDF
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
Mumbai B.Sc.IT Study
 
PDF
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Peng Cheng
 
PPTX
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
PPT
C++ tutorials
Divyanshu Dubey
 
Array within a class
AAKASH KUMAR
 
E7
lksoo
 
Generic programming and concepts that should be in C++
Anton Kolotaev
 
Data Structure Project File
Deyvessh kumar
 
Let Us Learn Lambda Using C# 3.0
Sheik Uduman Ali
 
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
I PUC CS Lab_programs
Prof. Dr. K. Adisesha
 
Data structures question paper anna university
sangeethajames07
 
20170317 functional programming in julia
岳華 杜
 
Cs 2003
Ravi Rajput
 
Network security CS6
Infinity Tech Solutions
 
Algorithms
Santosh Rajan
 
20170714 concurrency in julia
岳華 杜
 
[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
Peng Cheng
 
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
C++ tutorials
Divyanshu Dubey
 

Viewers also liked (20)

PPTX
Object Oriented Programming - Inheritance
Dudy Ali
 
PPTX
Object Oriented Programming - File Input & Output
Dudy Ali
 
PPTX
Java CRUD Mechanism with SQL Server Database
Dudy Ali
 
PPTX
Object Oriented Programming - Constructors & Destructors
Dudy Ali
 
PPTX
Database Introduction - Akses Data dengan SQL Server
Dudy Ali
 
PDF
Csharp_Chap03
Mohamed Krar
 
PDF
Lo2
liankei
 
PPT
Visula C# Programming Lecture 6
Abou Bakr Ashraf
 
DOCX
Differences between method overloading and method overriding
Pinky Anaya
 
PPTX
Object Oriented Programming with C#
foreverredpb
 
PPTX
Network Socket Programming with JAVA
Dudy Ali
 
PDF
Value Types
Michael Barker
 
PPT
Csc153 chapter 07
PCC
 
PPTX
Information System Security - Akuntabilitas dan Akses Kontrol
Dudy Ali
 
PPTX
Object Oriented Programming - Abstraction & Encapsulation
Dudy Ali
 
PPTX
Information System Security - Teknik Akses Kontrol
Dudy Ali
 
PPTX
Information System Security - Komponen Intranet dan Ekstranet
Dudy Ali
 
PPTX
Information System Security - Prinsip Manajemen Keamanan
Dudy Ali
 
PPTX
Information System Security - Konsep Manajemen Keamanan
Dudy Ali
 
DOCX
Diagram Konteks dan DFD Sistem Informasi Penjualan
Ricky Kusriana Subagja
 
Object Oriented Programming - Inheritance
Dudy Ali
 
Object Oriented Programming - File Input & Output
Dudy Ali
 
Java CRUD Mechanism with SQL Server Database
Dudy Ali
 
Object Oriented Programming - Constructors & Destructors
Dudy Ali
 
Database Introduction - Akses Data dengan SQL Server
Dudy Ali
 
Csharp_Chap03
Mohamed Krar
 
Lo2
liankei
 
Visula C# Programming Lecture 6
Abou Bakr Ashraf
 
Differences between method overloading and method overriding
Pinky Anaya
 
Object Oriented Programming with C#
foreverredpb
 
Network Socket Programming with JAVA
Dudy Ali
 
Value Types
Michael Barker
 
Csc153 chapter 07
PCC
 
Information System Security - Akuntabilitas dan Akses Kontrol
Dudy Ali
 
Object Oriented Programming - Abstraction & Encapsulation
Dudy Ali
 
Information System Security - Teknik Akses Kontrol
Dudy Ali
 
Information System Security - Komponen Intranet dan Ekstranet
Dudy Ali
 
Information System Security - Prinsip Manajemen Keamanan
Dudy Ali
 
Information System Security - Konsep Manajemen Keamanan
Dudy Ali
 
Diagram Konteks dan DFD Sistem Informasi Penjualan
Ricky Kusriana Subagja
 
Ad

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

PDF
C# p9
Renas Rekany
 
PPTX
Array,data type
veena_bhagyawani
 
PPS
05 iec t1_s1_oo_ps_session_07
Niit Care
 
PPT
17-Arrays en java presentación documento
DiegoGamboaSafla
 
PDF
Intake 38 3
Mahmoud Ouf
 
PPTX
Data structures in c#
SivaSankar Gorantla
 
PDF
Learn C# Programming - Nullables & Arrays
Eng Teong Cheah
 
PPTX
Intro to C# - part 2.pptx emerging technology
worldchannel
 
PPTX
Tophcjdjjdjsjssjjdkdkdkfkfkdfkdic-2.pptx
akoboty11
 
PPTX
Array lecture
Joan Saño
 
PDF
Array and Collections in c#
Umar Farooq
 
PPT
Visula C# Programming Lecture 5
Abou Bakr Ashraf
 
PPTX
Fundamentals of C# programming_Practical.pptx
dramaalghazi
 
PDF
C sharp chap6
Mukesh Tekwani
 
PPTX
C# lecture 2: Literals , Variables and Data Types in C#
Dr.Neeraj Kumar Pandey
 
PPTX
arrays in c# including Classes handling arrays
JayanthiM19
 
DOCX
Java R20 - UNIT-3.docx
Pamarthi Kumar
 
PPTX
ch 7 single dimension array in oop .pptx
nilampatoliya
 
PPTX
Java arrays
Mohammed Sikander
 
PPTX
Arrays in java
bhavesh prakash
 
Array,data type
veena_bhagyawani
 
05 iec t1_s1_oo_ps_session_07
Niit Care
 
17-Arrays en java presentación documento
DiegoGamboaSafla
 
Intake 38 3
Mahmoud Ouf
 
Data structures in c#
SivaSankar Gorantla
 
Learn C# Programming - Nullables & Arrays
Eng Teong Cheah
 
Intro to C# - part 2.pptx emerging technology
worldchannel
 
Tophcjdjjdjsjssjjdkdkdkfkfkdfkdic-2.pptx
akoboty11
 
Array lecture
Joan Saño
 
Array and Collections in c#
Umar Farooq
 
Visula C# Programming Lecture 5
Abou Bakr Ashraf
 
Fundamentals of C# programming_Practical.pptx
dramaalghazi
 
C sharp chap6
Mukesh Tekwani
 
C# lecture 2: Literals , Variables and Data Types in C#
Dr.Neeraj Kumar Pandey
 
arrays in c# including Classes handling arrays
JayanthiM19
 
Java R20 - UNIT-3.docx
Pamarthi Kumar
 
ch 7 single dimension array in oop .pptx
nilampatoliya
 
Java arrays
Mohammed Sikander
 
Arrays in java
bhavesh prakash
 
Ad

More from Dudy Ali (20)

PDF
Understanding COM+
Dudy Ali
 
PDF
Distributed Application Development (Introduction)
Dudy Ali
 
PPTX
Review Materi ASP.NET
Dudy Ali
 
PPTX
XML Schema Part 2
Dudy Ali
 
PPTX
XML Schema Part 1
Dudy Ali
 
PPTX
Rendering XML Document
Dudy Ali
 
PPTX
Pengantar XML
Dudy Ali
 
PPTX
Pengantar XML DOM
Dudy Ali
 
PPTX
Pengantar ADO.NET
Dudy Ali
 
PPTX
Database Connectivity with JDBC
Dudy Ali
 
PPTX
XML - Displaying Data ith XSLT
Dudy Ali
 
PPTX
Algorithm & Data Structure - Algoritma Pengurutan
Dudy Ali
 
PPTX
Algorithm & Data Structure - Pengantar
Dudy Ali
 
PPTX
Web Programming Syaria - Pengenalan Halaman Web
Dudy Ali
 
PPTX
Web Programming Syaria - PHP
Dudy Ali
 
PPTX
Software Project Management - Project Management Knowledge
Dudy Ali
 
PPTX
Software Project Management - Proses Manajemen Proyek
Dudy Ali
 
PPTX
Software Project Management - Pengenalan Manajemen Proyek
Dudy Ali
 
PPTX
System Analysis and Design - Unified Modeling Language (UML)
Dudy Ali
 
PPTX
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
Dudy Ali
 
Understanding COM+
Dudy Ali
 
Distributed Application Development (Introduction)
Dudy Ali
 
Review Materi ASP.NET
Dudy Ali
 
XML Schema Part 2
Dudy Ali
 
XML Schema Part 1
Dudy Ali
 
Rendering XML Document
Dudy Ali
 
Pengantar XML
Dudy Ali
 
Pengantar XML DOM
Dudy Ali
 
Pengantar ADO.NET
Dudy Ali
 
Database Connectivity with JDBC
Dudy Ali
 
XML - Displaying Data ith XSLT
Dudy Ali
 
Algorithm & Data Structure - Algoritma Pengurutan
Dudy Ali
 
Algorithm & Data Structure - Pengantar
Dudy Ali
 
Web Programming Syaria - Pengenalan Halaman Web
Dudy Ali
 
Web Programming Syaria - PHP
Dudy Ali
 
Software Project Management - Project Management Knowledge
Dudy Ali
 
Software Project Management - Proses Manajemen Proyek
Dudy Ali
 
Software Project Management - Pengenalan Manajemen Proyek
Dudy Ali
 
System Analysis and Design - Unified Modeling Language (UML)
Dudy Ali
 
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
Dudy Ali
 

Recently uploaded (20)

PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
July Patch Tuesday
Ivanti
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
July Patch Tuesday
Ivanti
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Biography of Daniel Podor.pdf
Daniel Podor
 

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 [email protected] Credits array content by : Yaddarabullah S.Kom M.Kom