Upload
meagan
View
39
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Hoofdstuk 9. Arrays. (poging 1). CirkelKlikker. int x, y;. void klik(object o, MouseEA mea) { }. this .x = mea.X; this .y = mea.Y; this .Invalidate();. void teken(object o, PaintEA pea) { }. Graphics gr = pea.Graphics;. tekent alleen laatste cirkel. - PowerPoint PPT Presentation
Citation preview
Hoofdstuk 9
Arrays
CirkelKlikker
void klik(object o, MouseEA mea){
}void teken(object o, PaintEA pea){
}
this.x = mea.X;this.y = mea.Y;this.Invalidate();
gr.FillEllipse(Brushes.Black, this.x, this.y, 15, 15 );
int x, y;
(poging 1)
Graphics gr = pea.Graphics;tekent alleenlaatste cirkel
CirkelKlikker
void klik(object o, MouseEA mea){
}
gr.FillEllipse(Brushes.Black, mea.x, mea.y, 15, 15 );
(poging 2)
Graphics gr = this.CreateGraphics();hertekent het
window nietwanneer nodig
CirkelKlikker
void klik(object o, MouseEA mea){
}void teken(object o, PaintEA pea){
}
this.x = mea.X;this.y = mea.Y;this.Invalidate();
gr.FillEllipse(Brushes.Black, this.x , this.y , 15, 15 );
int x, y;
(final version)
Graphics gr = pea.Graphics;
ARRAYfor (int t=0; t<n; t++)
[t] [t]
[n][n]
int n=0;[ ]
n++;
Arrays
Array: rij genummerde variabelen
tabel
0
1
2
3
4
length5
int [ ] tabel;
new int [5];
tabel =
declaratie vaneen array
creëren vanhet eigenlijkearray-object
Gebruik van een array
’t zijn echte variabelen:
tabel
0
1
2
3
4
length5tabel [2] = 37;
tabel[4] = tabel [2] + 5;
37
42
if (tabel.Length<10) ...
tabel.Length = 10;
Length is eenread-only property
Gebruik van een array
variabele als index in de array
tabel
0
1
2
3
4
length5tabel [0] = 42;tabel [1] = 42;tabel [2] = 42;tabel [3] = 42;tabel [4] = 42;
42
42
42
42
42
tabel [t] = 42;for (t=0; t<5; t++)
Array als parameter
tabel
0
1
2
3
4
length5
12
95
11
23
15
int Kleinste ( int [ ] tabel ){
}
int resultaat;
return resultaat;
if (tabel [t] < resultaat)
resultaat = tabel [t];
for (t=0; t<tabel.Length; t++)
int t;
resultaat =tabel [0];
Deel van de array doorzoeken
tabel
0
1
2
3
4
length5
12
95
11
int Kleinste ( int [ ] tabel ){
}
int resultaat;
return resultaat;
if (tabel [t] < resultaat)
resultaat = tabel [t];
for (t=0; t<tabel.Length; t++)
int t;
resultaat =tabel [0];aantal
, int aantal)static
CirkelKlikker
void teken(object o, PaintEA pea){
}
gr.FillEllipse(Brushes.Black, this.x[t], this.y[t], 15, 15) ;
int [ ] x, y; int n;
(final version)
Graphics gr = pea.Graphics;
ARRAY
for (int t=0; t<n; t++)
int minX = Bieb.Kleinste(x,n)–r;
int r=7;
int maxX = Bieb.Grootste(x,n)+r;int minY = Bieb.Kleinste(y,n)–r;int maxY = Bieb.Grootste(y,n)+r;gr.DrawRectangle(Brushes.Blue, minX, minY, maxX-minX, maxY-minY ) ;
Syntax van array-type
type
int
short
sbyte
long
decimal
double
float
char
bool
uint
ushort
byte
ulong
structnaam
classnaam
object
string
waard
everw
ijzin
g [ ]
,
arra
y
Array van getallen
tabel
int [ ] tabel;
new int [5];
tabel =
0
1
2
3
4
length5
Array van struct-objecten
tabel
Point [ ] tabel;
new Point[5];tabel =
0
1
2
3
4
length5
Array van class-objecten
tabel
Button [ ] tabel;
new Button[5];
tabel =
0
1
2
3
4
length5
for (int t=0; t<5; t++)
tabel[t] = new Button();
Twee-dimensionale array
tabel
int [ , ] tabel;
new int [5,3];
tabel =
0
1
2
3
4
length5
0 1
3
2tabel.GetLength(0)tabel.GetLength(1)
Array van arrays
tabel
int [ ] [ ] tabel;
new int[5][];tabel =
0
1
2
3
4
length5
for (int t=0; t<5; t++) tabel[t] = new int[t];
Drie-dimensionale array
tabel
int [ , , ] tabel;
new int [5,3,2];
tabel =
0
1
2
3
4
length5
0 1
3
2
2
01
Declaratiedeclaratie
naamtype
,
= initialisatieconst
;
var
met intitialisatie
initialisatie
expressie
initialisatie }{
,
string [ ] woorden = { "aap", "noot", "mies" };
int [ ] maand = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int [ , ] = { {1,2,3,4}, {5,6,7,8} };