SlideShare a Scribd company logo
1 of 43
Chapter 8 C# .NET Arrays
Pascal case AddUp(..) Camel case firstNumber C Programming Language case first_number a word on naming conventions
Why use Arrays? How to set up Array? Arrays and Loops Set size of Arrays at runtime Foreach loop What will we learn?
The variables we have been working with so far have only been able to hold one value at a time Example: int lotteryNumber1 = 1; int lotteryNumber2 = 2; int lotteryNumber3 = 3;    : An Array allows you to use just one identifying name that refers to lots of values Why use Arrays?
1. Declaration: int[] lotteryNumbers; float[] myFloatValues; string[] myStrings; 2. Size of array: lotteryNumbers = new int[4]; myFloatValues = new float[10]; myStrings = new string[5]; How to setup an Array
Declaration and setting the size in one line int[] lotteryNumbers = new int[4]; float[] myFloatValues = new float[10]; string[] myStrings = new string[5];
arrayName[position] = arrayValue; int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1;       // first array lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4;   // last (4th) array Assigning values
int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1;    lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4;  First index is ZERO
int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1;    lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4;  Last index is (SIZE -1)
int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1;    lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4;  Total number of array = SIZE
int[] lotteryNumbers = new int[4] {1, 2, 3, 4}; Declare, Set Array Size and Assign Values in one line Declare
int[] lotteryNumbers = new int[4] {1, 2, 3, 4}; Set Size of Array
int[] lotteryNumbers = new int[4] {1, 2, 3, 4}; Assign values
To loop through the following array: lotteryNumbers[0]  lotteryNumbers[1] lotteryNumbers[2]  lotteryNumbers[3]  for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i]     ….. // not complete } Part 2 Arrays and Loops
for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i]     ….. // not complete } starts from 0 The first index is ZERO
for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i]     ….. // not complete } Length is equal to the SIZE of array The last index should be (Length – 1)
for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i]     ….. // not complete } i < lotteryNumers.Length
for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i]     ….. // not complete } i <= lotteryNumers.Length -1
New Solution and project:  SpfChapter8 Save all Change the project name to "Part 2 Arrays and Loops" Add a button and a listBox Add codes into the button click method: Hands On
Use Loop
Use Loop
4
change the size of Array to 49:
Looping through from 2nd Array to last Array int() lotteryNumbers = int(5); for (inti=2; i != lotteryNumbers.Length; ++i) { lotteryNumbers(i) = 0; }  Spots the Errors
Why use Arrays? How to set up Array? Arrays and Loops Review
Set size of Arrays at runtime Foreach loop What will we learn?
The size of an array refers to how many items it holds But sometimes, you just don’t know how big the array needs to be – for example, when the application depends on user’s input during runtime Part 3 Set the Size of a C# array at RunTime
Add another button and textbox Continue from previous project
Add codes for button2 Click method:
The size of the array is set only during runtime
Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop
Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop loop through from 0 to (Length-1)  counter
Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop loop through from 0 to (Length-1)  counter individual element in array
Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop Individual element: arraySize[i] Individual element: number
Continue from previous project (Extra)
string Array is similar to integer Array     string[] arrayStrings; arrayStrings = new string[5]; foreach loop for string foreach (string arrayElement in arrayStrings) Using foreach with string Array
Continue from previous project
string array using for loop
string array using foreach

More Related Content

What's hot

Array in c language
Array in c languageArray in c language
Array in c language
home
 

What's hot (20)

C# programming language
C# programming languageC# programming language
C# programming language
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
C# String
C# StringC# String
C# String
 
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
C# basics
 C# basics C# basics
C# basics
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 

Viewers also liked

Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Lecture 3  data structures & algorithms - sorting techniques - http://techiem...Lecture 3  data structures & algorithms - sorting techniques - http://techiem...
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniques
Dharmendra Prasad
 
Csc153 chapter 06
Csc153 chapter 06Csc153 chapter 06
Csc153 chapter 06
PCC
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 

Viewers also liked (20)

Arrays
ArraysArrays
Arrays
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Lecture 2c stacks
Lecture 2c stacksLecture 2c stacks
Lecture 2c stacks
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Lecture 3  data structures & algorithms - sorting techniques - http://techiem...Lecture 3  data structures & algorithms - sorting techniques - http://techiem...
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
 
Array y Objects C#
Array y Objects C#Array y Objects C#
Array y Objects C#
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniques
 
Pascal
PascalPascal
Pascal
 
Arrays
ArraysArrays
Arrays
 
Csc153 chapter 06
Csc153 chapter 06Csc153 chapter 06
Csc153 chapter 06
 
C++ arrays part2
C++ arrays part2C++ arrays part2
C++ arrays part2
 
Arrays
ArraysArrays
Arrays
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
C
CC
C
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Sorting
SortingSorting
Sorting
 
Practicas sencillas para C#
Practicas sencillas para C# Practicas sencillas para C#
Practicas sencillas para C#
 

Similar to C# Arrays

spfchapter8arrays-100519221515-phpapp01.pdf
spfchapter8arrays-100519221515-phpapp01.pdfspfchapter8arrays-100519221515-phpapp01.pdf
spfchapter8arrays-100519221515-phpapp01.pdf
pepe3059
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
sotlsoc
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
irdginfo
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
Terry Yoast
 

Similar to C# Arrays (20)

spfchapter8arrays-100519221515-phpapp01.pdf
spfchapter8arrays-100519221515-phpapp01.pdfspfchapter8arrays-100519221515-phpapp01.pdf
spfchapter8arrays-100519221515-phpapp01.pdf
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
Array
ArrayArray
Array
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
07 Arrays
07 Arrays07 Arrays
07 Arrays
 
Array assignment
Array assignmentArray assignment
Array assignment
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: Arrays
 
Chap09
Chap09Chap09
Chap09
 
Arrays
ArraysArrays
Arrays
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Arrays
ArraysArrays
Arrays
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 

More from Hock Leng PUAH

CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Hock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
Hock Leng PUAH
 

More from Hock Leng PUAH (20)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

C# Arrays

  • 1. Chapter 8 C# .NET Arrays
  • 2. Pascal case AddUp(..) Camel case firstNumber C Programming Language case first_number a word on naming conventions
  • 3. Why use Arrays? How to set up Array? Arrays and Loops Set size of Arrays at runtime Foreach loop What will we learn?
  • 4. The variables we have been working with so far have only been able to hold one value at a time Example: int lotteryNumber1 = 1; int lotteryNumber2 = 2; int lotteryNumber3 = 3; : An Array allows you to use just one identifying name that refers to lots of values Why use Arrays?
  • 5. 1. Declaration: int[] lotteryNumbers; float[] myFloatValues; string[] myStrings; 2. Size of array: lotteryNumbers = new int[4]; myFloatValues = new float[10]; myStrings = new string[5]; How to setup an Array
  • 6. Declaration and setting the size in one line int[] lotteryNumbers = new int[4]; float[] myFloatValues = new float[10]; string[] myStrings = new string[5];
  • 7. arrayName[position] = arrayValue; int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1; // first array lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4; // last (4th) array Assigning values
  • 8. int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1; lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4; First index is ZERO
  • 9. int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1; lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4; Last index is (SIZE -1)
  • 10. int[] lotteryNumbers = new int[4]; lotteryNumbers[0] = 1; lotteryNumbers[1] = 2; lotteryNumbers[2] = 3; lotteryNumbers[3] = 4; Total number of array = SIZE
  • 11. int[] lotteryNumbers = new int[4] {1, 2, 3, 4}; Declare, Set Array Size and Assign Values in one line Declare
  • 12. int[] lotteryNumbers = new int[4] {1, 2, 3, 4}; Set Size of Array
  • 13. int[] lotteryNumbers = new int[4] {1, 2, 3, 4}; Assign values
  • 14. To loop through the following array: lotteryNumbers[0] lotteryNumbers[1] lotteryNumbers[2] lotteryNumbers[3] for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i] ….. // not complete } Part 2 Arrays and Loops
  • 15. for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i] ….. // not complete } starts from 0 The first index is ZERO
  • 16. for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i] ….. // not complete } Length is equal to the SIZE of array The last index should be (Length – 1)
  • 17. for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i] ….. // not complete } i < lotteryNumers.Length
  • 18. for (inti = 0; i != lotteryNumbers.Length; i++) { lotteryNumber[i] ….. // not complete } i <= lotteryNumers.Length -1
  • 19. New Solution and project: SpfChapter8 Save all Change the project name to "Part 2 Arrays and Loops" Add a button and a listBox Add codes into the button click method: Hands On
  • 21.
  • 23.
  • 24.
  • 25. 4
  • 26. change the size of Array to 49:
  • 27. Looping through from 2nd Array to last Array int() lotteryNumbers = int(5); for (inti=2; i != lotteryNumbers.Length; ++i) { lotteryNumbers(i) = 0; } Spots the Errors
  • 28. Why use Arrays? How to set up Array? Arrays and Loops Review
  • 29. Set size of Arrays at runtime Foreach loop What will we learn?
  • 30. The size of an array refers to how many items it holds But sometimes, you just don’t know how big the array needs to be – for example, when the application depends on user’s input during runtime Part 3 Set the Size of a C# array at RunTime
  • 31. Add another button and textbox Continue from previous project
  • 32. Add codes for button2 Click method:
  • 33. The size of the array is set only during runtime
  • 34. Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop
  • 35. Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop loop through from 0 to (Length-1) counter
  • 36. Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop loop through from 0 to (Length-1) counter individual element in array
  • 37. Compare for loop and foreach loop: for (int i = 0; i != arraySize.Length; i++) foreach (int number in arraySize) foreach loop Individual element: arraySize[i] Individual element: number
  • 38. Continue from previous project (Extra)
  • 39. string Array is similar to integer Array string[] arrayStrings; arrayStrings = new string[5]; foreach loop for string foreach (string arrayElement in arrayStrings) Using foreach with string Array
  • 41. string array using for loop
  • 42.