SlideShare a Scribd company logo
LECTURE 4
BY: RUBYNA VOHRA
AGENDA
• Arrays
WHAT IS AN ARRAY?
• An array stores a fixed-size sequential collection of elements of the same type. An
array is used to store a collection of data, but it is often more useful to think of an
array as a collection of variables of the same type stored at contiguous memory
locations.
• Think of it as a list of items
HOW DO ARRAYS WORK?
• Instead of declaring individual variables, such as number0, number1, ..., and
number99, you declare one array variable such as numbers and use numbers[0],
numbers[1], and ..., numbers[99] to represent individual variables.
• A specific element in an array is accessed by an index.
• All arrays consist of contiguous memory locations. The lowest address
corresponds to the first element and the highest address to the last element.
SYNTAX: DECLARING ARRAYS
• To declare an array in C#, you can use the following syntax −
• datatype[] arrayName;
• datatype is used to specify the type of elements in the array.
• [] specifies the size of the array.
• arrayName specifies the name of the array.
double[] balance;
SYNTAX: INITIALIZING THE ARRAY
• Declaring an array does not initialize the array in the memory. When the array
variable is initialized, you can assign values to the array.
• Array is a reference type, so you need to use the new keyword to create an
instance of the array.
• double[] balance = new double[10];
SYNTAX: ASSIGNING VALUES TO AN ARRAY
• You can assign values to individual array elements, by using the index number
• double[] balance = new double[10]; balance[0] = 4500.0;
• You can assign values to the array at the time of declaration
• double[] balance = { 2340.0, 4523.69, 3421.0};
• You can also create and initialize an array
• int [] marks = new int[5] { 99, 98, 92, 97, 95};
• You may also omit the size of the array
• int [] marks = new int[] { 99, 98, 92, 97, 95};
• You can copy an array variable into another target array variable. In such case, both the target and source point to
the same memory location −
• int [] marks = new int[] { 99, 98, 92, 97, 95};
int[] score = marks;
• When you create an array, C# compiler implicitly initializes each array element to a default value depending on the
array type. For example, for an int array all elements are initialized to 0.
SYNTAX: ACCESSING ARRAY ELEMENTS
• An element is accessed by indexing the array name.
• This is done by placing the index of the element within square brackets after the
name of the array.
• double salary = balance[9];
TRAVERSING THROUGH AN ARRAY
• When we want to update each value in an array, we can traverse through the
array
• Traversing is most commonly done using a for loop/for each loop
• SYNTAX:
for (int i = 0; i < 7; i++)
{
arrayName[i] = 20 + i;
}
PRINTING THE CONTENTS OF AN ARRAY
• We can print each item of the array using a for loop
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Element at index " + i + " = " + arrayName[i]);
}
REVIEWING THE FOR EACH LOOP
• For Each loop are used for collections
ARRAY CONCEPTS
LIVE WALKTHRU/EXPLANATION
WHAT ARE THE PRACTICAL USES OF AN ARRAY
• Arrays are the simplest data structures that stores items of the same data type.
• A basic application of Arrays can be storing data in tabular format.
• Examples:
• Contacts on our phone
• Games to track player moves (chess/checkers)
• Post office boxes
• Matrices/Grids
DISCUSSION
• Why is this important?
• How can this be useful to me?
• How can I use this in my current
job?
• How can I use this in my future
career?
• What will I get out of this?
• How is this used in the real world
Regroup and discuss after…
COMPLETE THE
WORKSHEET WITH
YOUR GROUP
Regroup and discuss after…

More Related Content

What's hot

Presentation about arrays
Presentation about arraysPresentation about arrays
Presentation about arrays
slave of Allah
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
Array in-c
Array in-cArray in-c
Array in-c
Samsil Arefin
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
Array1
Array1Array1
Array1
Rajendran
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
C
CC
Array
ArrayArray
ArrayHajar
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
Maulen Bale
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
Martin Chapman
 
Arrays
ArraysArrays
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
sudhirvegad
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4sotlsoc
 
Array C programming
Array C programmingArray C programming
Array C programming
Prionto Abdullah
 
Array in c language
Array in c languageArray in c language
Array in c language
umesh patil
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Visula C# Programming Lecture 5
Visula C# Programming Lecture 5Visula C# Programming Lecture 5
Visula C# Programming Lecture 5
Abou Bakr Ashraf
 

What's hot (20)

Presentation about arrays
Presentation about arraysPresentation about arrays
Presentation about arrays
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Array in-c
Array in-cArray in-c
Array in-c
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Array1
Array1Array1
Array1
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
C
CC
C
 
Array
ArrayArray
Array
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Arrays
ArraysArrays
Arrays
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
 
Array C programming
Array C programmingArray C programming
Array C programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Visula C# Programming Lecture 5
Visula C# Programming Lecture 5Visula C# Programming Lecture 5
Visula C# Programming Lecture 5
 

Similar to Lecture 4

Basics of array.pptx
Basics of array.pptxBasics of array.pptx
Basics of array.pptx
PRASENJITMORE2
 
Generative Coding Lecture notes using coding
Generative Coding Lecture notes using codingGenerative Coding Lecture notes using coding
Generative Coding Lecture notes using coding
ssuserff773c
 
Arrays
ArraysArrays
Arrays
swathi reddy
 
Array-part1
Array-part1Array-part1
Array-part1
AbishaiAsir
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
berekethailu2
 
CHAPTER-5.ppt
CHAPTER-5.pptCHAPTER-5.ppt
CHAPTER-5.ppt
Tekle12
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
Uma mohan
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 
Array
ArrayArray
Arrays
ArraysArrays
Mod 12
Mod 12Mod 12
Mod 12
obrienduke
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
Mudasir Syed
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
HarmanShergill5
 
Learn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & ArraysLearn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & Arrays
Eng Teong Cheah
 
C-Programming Arrays.pptx
C-Programming  Arrays.pptxC-Programming  Arrays.pptx
C-Programming Arrays.pptx
SKUP1
 
C-Programming Arrays.pptx
C-Programming  Arrays.pptxC-Programming  Arrays.pptx
C-Programming Arrays.pptx
LECO9
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
MANEESHValluru
 

Similar to Lecture 4 (20)

Basics of array.pptx
Basics of array.pptxBasics of array.pptx
Basics of array.pptx
 
Generative Coding Lecture notes using coding
Generative Coding Lecture notes using codingGenerative Coding Lecture notes using coding
Generative Coding Lecture notes using coding
 
Arrays
ArraysArrays
Arrays
 
Array-part1
Array-part1Array-part1
Array-part1
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
CHAPTER-5.ppt
CHAPTER-5.pptCHAPTER-5.ppt
CHAPTER-5.ppt
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
javaarray
javaarrayjavaarray
javaarray
 
Mod 12
Mod 12Mod 12
Mod 12
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Learn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & ArraysLearn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & Arrays
 
C-Programming Arrays.pptx
C-Programming  Arrays.pptxC-Programming  Arrays.pptx
C-Programming Arrays.pptx
 
C-Programming Arrays.pptx
C-Programming  Arrays.pptxC-Programming  Arrays.pptx
C-Programming Arrays.pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 

More from Skillspire LLC

Logistics
LogisticsLogistics
Logistics
Skillspire LLC
 
Introduction to analytics
Introduction to analyticsIntroduction to analytics
Introduction to analytics
Skillspire LLC
 
Review version 4
Review version 4Review version 4
Review version 4
Skillspire LLC
 
Review version 3
Review version 3Review version 3
Review version 3
Skillspire LLC
 
Review version 2
Review version 2Review version 2
Review version 2
Skillspire LLC
 

More from Skillspire LLC (20)

Logistics
LogisticsLogistics
Logistics
 
Introduction to analytics
Introduction to analyticsIntroduction to analytics
Introduction to analytics
 
Lecture 31
Lecture 31Lecture 31
Lecture 31
 
Lecture 30
Lecture 30Lecture 30
Lecture 30
 
Lecture 29
Lecture 29Lecture 29
Lecture 29
 
Review
ReviewReview
Review
 
Review version 4
Review version 4Review version 4
Review version 4
 
Review version 3
Review version 3Review version 3
Review version 3
 
Review version 2
Review version 2Review version 2
Review version 2
 
Lecture 25
Lecture 25Lecture 25
Lecture 25
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Lecture 23 p1
Lecture 23 p1Lecture 23 p1
Lecture 23 p1
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Lecture 15
Lecture 15Lecture 15
Lecture 15
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 13
Lecture 13Lecture 13
Lecture 13
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 

Lecture 4

  • 2.
  • 4. WHAT IS AN ARRAY? • An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. • Think of it as a list of items
  • 5. HOW DO ARRAYS WORK? • Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. • A specific element in an array is accessed by an index. • All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
  • 6. SYNTAX: DECLARING ARRAYS • To declare an array in C#, you can use the following syntax − • datatype[] arrayName; • datatype is used to specify the type of elements in the array. • [] specifies the size of the array. • arrayName specifies the name of the array. double[] balance;
  • 7. SYNTAX: INITIALIZING THE ARRAY • Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. • Array is a reference type, so you need to use the new keyword to create an instance of the array. • double[] balance = new double[10];
  • 8. SYNTAX: ASSIGNING VALUES TO AN ARRAY • You can assign values to individual array elements, by using the index number • double[] balance = new double[10]; balance[0] = 4500.0; • You can assign values to the array at the time of declaration • double[] balance = { 2340.0, 4523.69, 3421.0}; • You can also create and initialize an array • int [] marks = new int[5] { 99, 98, 92, 97, 95}; • You may also omit the size of the array • int [] marks = new int[] { 99, 98, 92, 97, 95}; • You can copy an array variable into another target array variable. In such case, both the target and source point to the same memory location − • int [] marks = new int[] { 99, 98, 92, 97, 95}; int[] score = marks; • When you create an array, C# compiler implicitly initializes each array element to a default value depending on the array type. For example, for an int array all elements are initialized to 0.
  • 9. SYNTAX: ACCESSING ARRAY ELEMENTS • An element is accessed by indexing the array name. • This is done by placing the index of the element within square brackets after the name of the array. • double salary = balance[9];
  • 10. TRAVERSING THROUGH AN ARRAY • When we want to update each value in an array, we can traverse through the array • Traversing is most commonly done using a for loop/for each loop • SYNTAX: for (int i = 0; i < 7; i++) { arrayName[i] = 20 + i; }
  • 11. PRINTING THE CONTENTS OF AN ARRAY • We can print each item of the array using a for loop for (int i = 0; i < 10; i++) { Console.WriteLine("Element at index " + i + " = " + arrayName[i]); }
  • 12. REVIEWING THE FOR EACH LOOP • For Each loop are used for collections
  • 15.
  • 16. WHAT ARE THE PRACTICAL USES OF AN ARRAY • Arrays are the simplest data structures that stores items of the same data type. • A basic application of Arrays can be storing data in tabular format. • Examples: • Contacts on our phone • Games to track player moves (chess/checkers) • Post office boxes • Matrices/Grids
  • 17.
  • 18. DISCUSSION • Why is this important? • How can this be useful to me? • How can I use this in my current job? • How can I use this in my future career? • What will I get out of this? • How is this used in the real world Regroup and discuss after…
  • 19.
  • 20. COMPLETE THE WORKSHEET WITH YOUR GROUP Regroup and discuss after…