Documente Academic
Documente Profesional
Documente Cultură
using System;
class SingleDimArrayApp
{
protected int[] numbers;
SingleDimArrayApp()
{
numbers = new int[6];
for (int i = 0; i < 6; i++)
{
numbers[i] = i * i;
}
}
numbers[0]=0
numbers[1]=1
numbers[2]=4
numbers[3]=9
numbers[4]=16
numbers[5]=25
In this example, the SingleDimArray.PrintArray method uses
theSystem.Array Length property to determine the number of
elements in the array. It's not obvious here, since we have only a
single-dimensional array, but the Length property actually returns the
number of all the elements in all the dimensions of an array.
Therefore, in the case of a two dimensional array of 5 by 4,
theLength property would return 9. In the next section, I'll look at
multidimensional arrays and how to determine the upper bound of a
specific array dimension.
double[,,] numbers;
using System;
class MultiDimArrayApp
{
protected int currentMonth;
protected double[,] sales;
MultiDimArrayApp()
{
currentMonth=10;
[0][0]=0
[0][1]=1
[0][2]=2
[0][3]=3
[0][4]=4
[0][5]=5
[0][6]=6
[0][7]=7
[0][8]=8
[0][9]=9
[1][0]=100
[1][1]=101
[1][2]=102
[1][3]=103
[1][4]=104
[1][5]=105
[1][6]=106
[1][7]=107
[1][8]=108
[1][9]=109