int [] a = new int [4];

8
1 dimensional static Array Int[] a = new int[4]; A[0 ] A[1 ] A[2 ] A[3 ] Int[] b= new int[1]; B[0 ] Array is a list of variables having same name and same data type but accessed using index number A[2]=10; 10 string[] b = new string[6];

Upload: gunnar

Post on 22-Feb-2016

51 views

Category:

Documents


0 download

DESCRIPTION

Int [] a = new int [4];. Array is a list of variables having same name and same data type but accessed using index number. A[0]. A[1]. A[2]. A[3]. 10. Int[] b= new int[1];. B[0]. A[2]=10;. string[] b = new string[6]; . String[] n; n= new string[3]; n[0]=“faisal”; n[1]=“Israr”; - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Int [] a = new  int [4];

1 dimensional static Array

Int[] a = new int[4];A[0]

A[1]

A[2]

A[3]

Int[] b= new int[1];B[0]

Array is a list of variables having same name and same data type but accessed using index number

A[2]=10;

10

string[] b = new string[6];

Page 2: Int [] a = new  int [4];

String[] n;n= new string[3];n[0]=“faisal”;n[1]=“Israr”;n[2]=“javed”;

n[0] n[1] n[2]n is nothing

n[0] n[1] n[2]

faisal Israr javed

String[] n={“faisal”,”Israr”,”javed”};

1 dimensional static Array

Page 3: Int [] a = new  int [4];

• string[] weekDays = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

• int[] array3; • array3 = new int[] { 1, 3, 5, 7, 9 }; // OK • array3 = {1, 3, 5, 7, 9}; // Error

1 dimensional static Array

Page 4: Int [] a = new  int [4];

Multi dimensional array

Int[,] n = new int[1][1];

int[,] n = new int[2,3];

n[0,0]

0

0

0 1 20

1

n[0,2]

int[, ,] n = new int[2,3, 3];

01

0 1 2

0

1

2

n[1,0,2]

Page 5: Int [] a = new  int [4];

More Examples

• int[,] arr2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

• int[, ,] arr3D = new int[,,] { { { 1, 2, 3 } }, { { 4, 5, 6 } } };

• int[,] array4 = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

• int[,] array5;• array5 = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

// OK • array5 = {{1,2}, {3,4}, {5,6}, {7,8}};

// Error

Page 6: Int [] a = new  int [4];

Jagged arrays

int[][] a= new int[][]; a = new int[0][3]; a= new int[1][1];

0 1 20

1

3

a[1][1]

Int[][] a;a=new int[1][1] {}A[0]=new integer[3]{}A[1]=new integer[1]{}0 1 2

0

1

3

a[1][1]

Page 7: Int [] a = new  int [4];

Jagged Array• int[][] jaggedArray2 = new int[][] • { • new int[] {1,3,5,7,9},• new int[] {0,2,4,6},• new int[] {11,22}• };

• int[][,] jaggedArray4 = new int[3][,] • {• new int[,] { {1,3}, {5,7} },• new int[,] { {0,2}, {4,6}, {8,10} }, • new int[,] { {11,22}, {99,88}, {0,9} }• };

Page 8: Int [] a = new  int [4];

Conclusion

QUESTIONS ?