SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
C#.NET
C#.NETC#.NET
C#.NET
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
 
C# String
C# StringC# String
C# String
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Intoduction to structure
Intoduction to structureIntoduction to structure
Intoduction to structure
 
Strings in c#
Strings in c#Strings in c#
Strings in c#
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
C# basics
 C# basics C# basics
C# basics
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
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).pptxEsquimalt MFRC
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
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 FellowsMebane Rash
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
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_.pdfSherif Taha
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
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.pdfDr Vijay Vishwakarma
 
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.pptxheathfieldcps1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 

Kürzlich hochgeladen (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
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
 
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
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
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
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.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
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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
 
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
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

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.