Join Anton Delsink for an in-depth discussion in this video IEnumerable and yield return, part of Object Oriented Programming with C#.
- [Instructor] Now that we've seen the typical pattern…for reading files, and especially with a stream reader,…we were reading a line at a time…until there's no lines remaining in the file,…let's reintroduce the IEnumerable interface here.…In this case, I'll copy the whole method.…Ctrl-C.…Ctrl-V.…Let's call it 16.…And now, I'm going to extract the part…that is saying a line equals sr.ReadLine…into a separate method.…
So I will select the text,…the y loop, the string initialization,…but not the first ReadLine.…And now, I will extract the method,…Ctrl-R for a factor followed by M.…And so remember to hold down Ctrl…for both keystrokes, Ctrl-R-M.…And that gets us the extract method, refactoring.…And so I'll call this GetData and it takes as input, sr,…the stream reader we've just set up.…
And so you can see now that we have a very simple method…that is given a stream reader.…It will loop through all of the lines of text…in that stream reader, and return.…Now, that's not quite what we would like.…I would obviously want to have access to the data.…
- 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.