SlideShare a Scribd company logo
Chapter 8C# .NET Arrays
Pascal caseAddUp(..)Camel casefirstNumberC Programming Language casefirst_numbera word on naming conventions
Why use Arrays?How to set up Array?Arrays and LoopsSet size of Arrays at runtimeForeach loopWhat will we learn?
The variables we have been working with so far have only been able to hold one value at a timeExample:int lotteryNumber1 = 1;int lotteryNumber2 = 2;int lotteryNumber3 = 3;   :An Array allows you to use just one identifying name that refers to lots of valuesWhy 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 lineint[] 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 arraylotteryNumbers[1] = 2;lotteryNumbers[2] = 3;lotteryNumbers[3] = 4;   // last (4th) arrayAssigning 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 lineDeclare
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 0The first index is ZERO
for (inti = 0; i != lotteryNumbers.Length; i++){lotteryNumber[i]     ….. // not complete}Length is equal to the SIZE of arrayThe 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:  SpfChapter8Save allChange the project name to "Part 2 Arrays and Loops"Add a button and a listBoxAdd codes into the button click method:Hands On
Use Loop
C# Arrays
Use Loop
C# Arrays
C# Arrays
4
change the size of Array to 49:
Looping through from 2nd Array to last Arrayint() 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 LoopsReview
Set size of Arrays at runtimeForeach loopWhat will we learn?
The size of an array refers to how many items it holdsBut sometimes, you just don’t know how big the array needs to be – for example, when the application depends on user’s input during runtimePart 3 Set the Size of a C# array at RunTime
Add another button and textboxContinue 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 looploop 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 looploop through from 0 to (Length-1) counterindividual element in array
Compare for loop and foreach loop:for (int i = 0; i != arraySize.Length; i++)foreach (int number in arraySize)foreach loopIndividual 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 stringforeach (string arrayElement in arrayStrings)Using foreach with string Array
Continue from previous project
string array using for loop
C# Arrays
string array using foreach

More Related Content

What's hot (20)

PPTX
Arrays in Java
Abhilash Nair
 
PPTX
JAVA AWT
shanmuga rajan
 
PPT
C# basics
Dinesh kumar
 
PPT
sets and maps
Rajkattamuri
 
PPTX
Triggers
Pooja Dixit
 
PPT
Introduction to c#
OpenSource Technologies Pvt. Ltd.
 
PPSX
ASP.NET Web form
Md. Mahedee Hasan
 
PDF
Constructors and Destructors
Dr Sukhpal Singh Gill
 
PPTX
Data structure and algorithm using java
Narayan Sau
 
PPT
Java Servlets
BG Java EE Course
 
PPTX
Interface in java
PhD Research Scholar
 
PDF
Collections In Java
Binoj T E
 
PPTX
String in java
Ideal Eyes Business College
 
PPTX
Arrays C#
Raghuveer Guthikonda
 
PPT
Introduction to .NET Framework
Raghuveer Guthikonda
 
PPTX
CSharp Presentation
Vishwa Mohan
 
PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PPTX
Pointers in c++
Vineeta Garg
 
Arrays in Java
Abhilash Nair
 
JAVA AWT
shanmuga rajan
 
C# basics
Dinesh kumar
 
sets and maps
Rajkattamuri
 
Triggers
Pooja Dixit
 
ASP.NET Web form
Md. Mahedee Hasan
 
Constructors and Destructors
Dr Sukhpal Singh Gill
 
Data structure and algorithm using java
Narayan Sau
 
Java Servlets
BG Java EE Course
 
Interface in java
PhD Research Scholar
 
Collections In Java
Binoj T E
 
Introduction to .NET Framework
Raghuveer Guthikonda
 
CSharp Presentation
Vishwa Mohan
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Pointers in c++
Vineeta Garg
 

Viewers also liked (20)

PPT
Arrays
archikabhatia
 
PDF
Lecture17 arrays.ppt
eShikshak
 
PPTX
Array in C# 3.5
Gopal Ji Singh
 
PPTX
Array in c language
home
 
DOC
Arrays In General
martha leon
 
PPT
Lecture 2c stacks
Victor Palmar
 
PPSX
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
PPTX
Array y Objects C#
Manuel Antonio
 
PPSX
Lecture 2 data structures & algorithms - sorting techniques
Dharmendra Prasad
 
PDF
Pascal
Ezeodum Austin
 
PPTX
Arrays
Trupti Agrawal
 
PPT
Csc153 chapter 06
PCC
 
PDF
C++ arrays part2
Subhasis Nayak
 
PPTX
Arrays
Peter Andrews
 
PPT
Lecture 2a arrays
Victor Palmar
 
PDF
Learning VB.NET Programming Concepts
guest25d6e3
 
PPTX
queue & its applications
somendra kumar
 
PPT
Arrays Class presentation
Neveen Reda
 
PPT
Sorting
Ghaffar Khan
 
Lecture17 arrays.ppt
eShikshak
 
Array in C# 3.5
Gopal Ji Singh
 
Array in c language
home
 
Arrays In General
martha leon
 
Lecture 2c stacks
Victor Palmar
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
Array y Objects C#
Manuel Antonio
 
Lecture 2 data structures & algorithms - sorting techniques
Dharmendra Prasad
 
Csc153 chapter 06
PCC
 
C++ arrays part2
Subhasis Nayak
 
Lecture 2a arrays
Victor Palmar
 
Learning VB.NET Programming Concepts
guest25d6e3
 
queue & its applications
somendra kumar
 
Arrays Class presentation
Neveen Reda
 
Sorting
Ghaffar Khan
 
Ad

Similar to C# Arrays (20)

PDF
spfchapter8arrays-100519221515-phpapp01.pdf
pepe3059
 
PPTX
arrays-120712074248-phpapp01
Abdul Samee
 
PPTX
Loops in C# for loops while and do while loop.
Abid Kohistani
 
PPTX
Visual Programing basic lectures 7.pptx
Mrhaider4
 
PPT
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
 
PDF
C sharp chap6
Mukesh Tekwani
 
PPTX
C# basics
sagaroceanic11
 
PPTX
Chapter 2
application developer
 
PPT
07 Arrays
maznabili
 
PPT
Csphtp1 07
HUST
 
PPTX
arrays in c# including Classes handling arrays
JayanthiM19
 
PPTX
Intro to C# - part 2.pptx emerging technology
worldchannel
 
PPTX
16. Arrays Lists Stacks Queues
Intro C# Book
 
DOCX
Oops pramming with examples
Syed Khaleel
 
PDF
C# p9
Renas Rekany
 
PPT
Strings Arrays
phanleson
 
PPT
Mesics lecture 8 arrays in 'c'
eShikshak
 
PPT
For Beginners - C#
Snehal Harawande
 
PPTX
07. Arrays
Intro C# Book
 
PPTX
Session#2
Mohamed Samir
 
spfchapter8arrays-100519221515-phpapp01.pdf
pepe3059
 
arrays-120712074248-phpapp01
Abdul Samee
 
Loops in C# for loops while and do while loop.
Abid Kohistani
 
Visual Programing basic lectures 7.pptx
Mrhaider4
 
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
 
C sharp chap6
Mukesh Tekwani
 
C# basics
sagaroceanic11
 
07 Arrays
maznabili
 
Csphtp1 07
HUST
 
arrays in c# including Classes handling arrays
JayanthiM19
 
Intro to C# - part 2.pptx emerging technology
worldchannel
 
16. Arrays Lists Stacks Queues
Intro C# Book
 
Oops pramming with examples
Syed Khaleel
 
Strings Arrays
phanleson
 
Mesics lecture 8 arrays in 'c'
eShikshak
 
For Beginners - C#
Snehal Harawande
 
07. Arrays
Intro C# Book
 
Session#2
Mohamed Samir
 
Ad

More from Hock Leng PUAH (20)

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

Recently uploaded (20)

PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Difference between write and update in odoo 18
Celine George
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
epi editorial commitee meeting presentation
MIPLM
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 

C# Arrays

  • 2. Pascal caseAddUp(..)Camel casefirstNumberC Programming Language casefirst_numbera word on naming conventions
  • 3. Why use Arrays?How to set up Array?Arrays and LoopsSet size of Arrays at runtimeForeach loopWhat will we learn?
  • 4. The variables we have been working with so far have only been able to hold one value at a timeExample:int lotteryNumber1 = 1;int lotteryNumber2 = 2;int lotteryNumber3 = 3; :An Array allows you to use just one identifying name that refers to lots of valuesWhy 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 lineint[] 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 arraylotteryNumbers[1] = 2;lotteryNumbers[2] = 3;lotteryNumbers[3] = 4; // last (4th) arrayAssigning 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 lineDeclare
  • 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 0The first index is ZERO
  • 16. for (inti = 0; i != lotteryNumbers.Length; i++){lotteryNumber[i] ….. // not complete}Length is equal to the SIZE of arrayThe 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: SpfChapter8Save allChange the project name to "Part 2 Arrays and Loops"Add a button and a listBoxAdd codes into the button click method:Hands On
  • 25. 4
  • 26. change the size of Array to 49:
  • 27. Looping through from 2nd Array to last Arrayint() 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 LoopsReview
  • 29. Set size of Arrays at runtimeForeach loopWhat will we learn?
  • 30. The size of an array refers to how many items it holdsBut sometimes, you just don’t know how big the array needs to be – for example, when the application depends on user’s input during runtimePart 3 Set the Size of a C# array at RunTime
  • 31. Add another button and textboxContinue 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 looploop 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 looploop through from 0 to (Length-1) counterindividual element in array
  • 37. Compare for loop and foreach loop:for (int i = 0; i != arraySize.Length; i++)foreach (int number in arraySize)foreach loopIndividual 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 stringforeach (string arrayElement in arrayStrings)Using foreach with string Array