COPRO-3 (Computer Programming 3 - C# Programming) Bachelor of Science in Information Technology 2A & 2B PREFINAL Arrays Arrays Collection of data elements of the same type that are referred together by a common name. Acts like grouped variables which enable to store many values in a single array variable. Individual variable in an array is accessed through a subscript or an index. Subscript Also called index A number which specifies the number of items (elements) within an array By default, its value starts with 0, so the value of last element is one less than the total element in an array.
Elements of an Array Array Name: A valid variable name for the structure Subscript or Index: A value that refers to a particular array element Element: An individual data item within an array. Single-Dimensional Array One-dimensional array An array with element identified by a single subscript Stores only single set of data. Multidimensional Array Also known as array of arrays because its element are arrays Used to hold pair of even triplets of values Two-Dimensional Array Also called as rectangular array A multidimensional array with two upper subscript Has two indices where: first index identifies the row; second index identifies the column.
Arrays
Page 1 of 2
COPRO-3 (Computer Programming 3 - C# Programming) Bachelor of Science in Information Technology 2A & 2B Jagged Array An array where each row has different length Allows grouping a few arrays of different sizes into single array.
Declaring an Array Declared with the name of the array, size is the last element in array, and type is the data type that can be stored in the array Basic syntax for declaring single-dimensional array: Syntax: type[]array-name = new type[size]; Example int[]Arr = new int[10]; Basic syntax for declaring two-dimensional array: Syntax: type[][]array-name = new type[size_row][size_col]; Example int[][]grade = new int[5][10];