
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















12_arrays_loading.ppt
int intQty1, intQty2, intQty3;
int[ ] intQty = new int[3]; //3 integer variables
dataType[ ] arrayName = new dataType[arraySize];
memory to allocate.
are loaded in we don’t want to lose the values.
int[ ] intQty = new int[3]; //3 integer variables
Position Address Index Value 1 1010 [0] 0
2 1014 [1] 0
3 1018 [2] 0
4 1022 [3] 0
5 1026 [4] 0 6 1030 [5] 0
7 1034 [6] 0
… … … …
20 1086 [19] 0
Position Address Index Value
1 1010 [0] 50
2 1014 [1] 40
3 1018 [2] 100
4 1022 [3] 30
5 1026 [4] 10
6 1030 [5] 20
7 1034 [6] 0
… … … …
20 1086 [19] 0
Process Array – Individual Elements
private void btnProcessArray_Click( )
{ int i; int intSum = 0;
for (i = 0; i <= cintTestScores.GetUpperBound(0); i++) { intSum += cintTestScores[i]; }
txtSum.Text = intSum.ToString(“N0”);
}
Individual Elements as Arguments
private void btnProcessArray_Click( )
{ int i; decimal decPercent;
for (i = 0; i <= cintTestScores.GetUpperBound(0); i++) { decPercent = calcPercent( cintTestScores[i] ); txtPercent.Text = decPercent.ToString(“N0”); }
}
private decimal calcPercent(int intScore )
{ return (intScore / 100);
} Docsity.com