Join Gerry O'Brien for an in-depth discussion in this video Building foreach loops, part of Learning C#.
In this case, we've declared something called int arrInts.…So, the square brackets at the end of this tells us that…we're creating something called an array, which is one type of a collection.…We've given it a name called arrInts and we have…assigned some values, 3, 5, 6, 23, 95, 45, 32.…So we throw in some values into this array.…An array is just simply a in-memory representation or a…collection of specific values and in this case, integer values.…I've created that because I wanted you to see how the foreach loop works.…
Up here we simply counted up to ten or up…to nine, because we did less than ten up here.…In this case, we actually have a collection…of values that we're going to iterate over.…So, that's key.…When you think about foreach, think about iteration.…Within our foreach parentheses, we say foreach, int item.…So I've declared a data type of integer called int.…I've given it a name called item.…And I said, for each integer item that's in my array int.…
So, within this integer array, I want you to do a Comsole.WriteLine item.…
- Installing C#
- Working with loops
- Controlling program flow
- Using variables
- Building functions
- Creating and instantiating classes
- Catching errors
- Managing resources with the garbage collector
- Building collections
Skill Level Beginner
1. Introducing C#
2. C# Language Elements
3. Object-Oriented Programming in C#
4. Structured Exception Handling
5. Resource Management in C#
6. Extensible Types in C#
7. Windows Apps in C#
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.