Week 01

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Mansoura University

Faculty of Computers and Information Sciences


First Semester 2023-2024

Object Oriented Programming


(OOP)
Week: 01
Grade: 1st
Eng. Amany Sherif | Computer Science Department
Table of contents

01 02
1D Array 2D Array
What’s Array:

Array: are a collection of values that all share the same data type.
• You could have an array of type string that contains a list of student
names, or an array of type int that stores a collection of user ids.

1D Array declaration:
1D Array initilization:
Access the Elements of an Array:
• You access an array element by referring to the index number.

Change an Array Element


• To change the value of a specific element, refer to the index
number:
Array Length:
To find out how many elements an array has, use the Length property:

Change an Array Element


• To change the value of a specific element, refer to the index
number:
Loop through Array:
You can loop through the array elements with the for loop, and use
the Length property to specify how many times the loop should run:
Getting the array Max item:
Getting the array Min item:
Getting the summation of the array item:
Multi Dimensional Array:
• A multidimensional array is basically an array of arrays.
• Arrays can have any number of dimensions.
• The most common are two-dimensional arrays (2D).
• To create a 2D array, add each array within its own set of curly
braces, and insert a comma (,) inside the square brackets:
Access elements of a 2D Array:
• To access an element of a two-dimensional array, you must
specify two indexes: one for the array, and one for the element
inside that array.
• This statement accesses the value of the element in the first row
(0) and third column (2) of the numbers array:
Change elements of a 2D Array:
• The following example will change the value of the element in
the first row (0) and first column (0):
Loop through 2D Array:
You can easily loop through the elements of a two-dimensional
array with a foreach loop:
Loop through 2D Array:
You can loop also through the elements of a two-dimensional array
with a for loop:
Thanks!
Do you have any questions?
amanysherif@mans.edu.eg

You might also like