Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1110: Computer Science I Chapter 5 Arrays. One-dimensional Arrays int [] data = new int [4]; data[0] = 1; data[1] = 3; data[2] = 5; data[3] = 7; Arrays.

Similar presentations


Presentation on theme: "CS1110: Computer Science I Chapter 5 Arrays. One-dimensional Arrays int [] data = new int [4]; data[0] = 1; data[1] = 3; data[2] = 5; data[3] = 7; Arrays."— Presentation transcript:

1 CS1110: Computer Science I Chapter 5 Arrays

2 One-dimensional Arrays int [] data = new int [4]; data[0] = 1; data[1] = 3; data[2] = 5; data[3] = 7; Arrays are reference type Arrays are created by using new Array size cannot be changed once created

3 Indexing an Array Element For an array int [] X = new int [length]; We can use X[i] to access an element 0<=i<=length-1

4 Array Initialization int [] a = new int[2]; Numeric types are initialized to 0, bool types are initialized to false A[0]=10; a[1]=20; int [] a = new int[2] {10, 20}; int [] a = {10, 20}; a.length can be used to determine the number of elements

5 System.Array.Copy() method public static void Copy(T from[], T to[], int howMany); public static void Copy(T from[], int fromI, T to[], int toI, int howMany);


Download ppt "CS1110: Computer Science I Chapter 5 Arrays. One-dimensional Arrays int [] data = new int [4]; data[0] = 1; data[1] = 3; data[2] = 5; data[3] = 7; Arrays."

Similar presentations


Ads by Google