SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (20)

Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
C#.NET
C#.NETC#.NET
C#.NET
 
C# String
C# StringC# String
C# String
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
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# loops
C# loopsC# loops
C# loops
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
C# basics
 C# basics C# basics
C# basics
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1
 

En vedette

Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppteShikshak
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In Generalmartha 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 techniquesDharmendra Prasad
 
Csc153 chapter 06
Csc153 chapter 06Csc153 chapter 06
Csc153 chapter 06PCC
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Conceptsguest25d6e3
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 

En vedette (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
 
Array in c language
Array in c languageArray in c language
Array in c language
 
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
 

Similaire à C# Arrays

spfchapter8arrays-100519221515-phpapp01.pdf
spfchapter8arrays-100519221515-phpapp01.pdfspfchapter8arrays-100519221515-phpapp01.pdf
spfchapter8arrays-100519221515-phpapp01.pdfpepe3059
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1sotlsoc
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injavairdginfo
 
Array assignment
Array assignmentArray assignment
Array assignmentAhmad Kamal
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: ArraysMartin Chapman
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programmingTaseerRao
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
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.pdfajajkhan16
 

Similaire à 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
 

Plus de Hock Leng PUAH

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image SlideshowHock Leng PUAH
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introductionHock Leng PUAH
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingHock Leng PUAH
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash fileHock Leng PUAH
 
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 birthHock Leng PUAH
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime exampleHock Leng PUAH
 
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( ) functionHock Leng PUAH
 
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 siteHock Leng PUAH
 
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 visibleHock Leng PUAH
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common ErrorsHock 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 ProjectHock Leng PUAH
 
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 parallelHock Leng PUAH
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises GuideHock Leng PUAH
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connectionHock Leng PUAH
 
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 SummaryHock Leng PUAH
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guideHock Leng PUAH
 

Plus de 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
 

Dernier

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Dernier (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

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.