-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFig-7.03 - InitArray.cs
More file actions
40 lines (29 loc) · 847 Bytes
/
Copy pathFig-7.03 - InitArray.cs
File metadata and controls
40 lines (29 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Fig. 7.3: InitArray.cs
// Diferentes maneiras de inicializar arrays.
using System;
using System.Windows.Forms;
public class InitArray : Form
{
static void Main(string[] args)
{
string output = "";
int[] x;
x = new int[10];
// A lista inicializadora especifica o número de elementos
// e o valor de cada elemento.
int[] y = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
const int ARRAY_SIZE = 10;
int[] z;
z = new int[ARRAY_SIZE];
// Configura os valores no array.
for (int i = 0; i < z.Length; i++)
z[i] = 2 + 2 * i;
output += "Subscript\tArray x\tArray y\tArray z\n";
for (int i = 0; i < ARRAY_SIZE; i++)
output += i + "\t\t" + x[i] + "\t" + y[i] + "\t" + z[i] + "\n";
MessageBox.Show(output,
"Initializing an array of int values",
MessageBoxButtons.OK, MessageBoxIcon.Information
);
}
}