Join Anton Delsink for an in-depth discussion in this video IEnumerable and foreach, part of Object Oriented Programming with C#.
- [Instructor] Now that we've seen that a collection like…list of int implements the IEnumerable interface…and can give us an enumerator object,…let's see how we would use that in a typical scenario…where there are multiple elements in the collection.…I'll copy the whole unit test from line nine through to 24.…The whole method, copy.…Paste.…Rename the method to number two.…And scroll down to here.…Now, remember the enumerator object will let us access…each element in the collection.…
So the next step is now to literally loop through,…go through all of the elements in the collection…until we've exhausted them.…And so what we want to do is ask for…e.MoveNext multiple times.…So we can say in this pattern, while…e.MoveNext is true, run all of the following code.…And so in this example,…we're one step closer to a foreach…in that we will call MoveNext…on the enumerator.…And if MoveNext is true, we will drop in here…and read the current value from the enumerator.…
That means the first time the value will be one.…Second time, the value will be three, and so forth.…
- Abstract classes
- Processing text with StreamReader
- IEnumerable and yield return
- Windows Forms controls
- Windows Forms with and without the designer
- Adding, organizing, and testing forms
- Creating classes
Skill Level Intermediate
What you should know1m 10s
1. Theory vs. Practice
2. Examples from .NET
3. Examples from Windows UI
4. Examples from Board Games
5. Examples from the Web
Next steps1m 13s
- 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.