Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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];

2 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] faisalIsrarjaved String[] n={“faisal”,”Israr”,”javed”}; 1 dimensional static Array

3 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

4 Multi dimensional array Int[,] n = new int[1][1]; int[,] n = new int[2,3]; n[0,0]0 0 012 0 1 n[0,2] int[,,] n = new int[2,3, 3]; 0 1 012 0 1 2 n[1,0,2]

5 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

6 Jagged arrays int[][] a= new int[][]; a = new int[0][3]; a= new int[1][1]; 012 0 1 3 a[1][1] Int[][] a; a=new int[1][1] {} A[0]=new integer[3]{} A[1]=new integer[1]{} 012 0 1 3 a[1][1]

7 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} } };

8 Conclusion QUESTIONS ?


Download ppt "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."

Similar presentations


Ads by Google