Escolar Documentos
Profissional Documentos
Cultura Documentos
Módulo 6: Arrays
1
Arrays
índice = 0 índice = 4
2
Notação
type[ ] name;
nome da variável
dimensão
tipo de dados
3
Dimensão
Vector
long[ ] row;
type[ ] name;
...
Matriz
type[ , ] row[3];
name;
int[ , ] grid;
...
grid[2,3];
Array tridimensional
type[ , , ] name;
etc…
4
Verificação dos limites
row.GetLength(0) == 5 grid.GetLength(0) == 2
row.Length == 5 grid.GetLength(0) == 5
row.Length == 2*5
5
Criação
Inicialização
Declaração
...
row[1] = 0L;
6
Propriedades e métodos
row.Rank
row.Length
7
Passagem por parâmetro
class Example2 {
static void Main(){
int[] arg = {10, 9, 8, 7};
Method(arg);
System.Console.WriteLine(arg[0]);
}
static void Main(int[] parameter) {
parameter[0]++;
}
}
8
foreach
class Example4 {
static void Main(string[ ] args) {
foreach (string arg in args) {
System.Console.WriteLine(arg);
}
}
}
9
Exercício
int [ ] array;
array = {0, 2, 4, 6}
int [ ] array;
System.Console.WriteLine(array[0]);