Using a `for` Loop4:13 with James Churchill
In this video, we'll introduce our first challenge—using a `for` loop to loop through our Media Library items and output each item's information to the console.
This practice session assumes that you've completed stage 6 of the C# Objects course. If you haven't done that yet, go check it out, then come back to this workshop.
This practice session also builds upon the skills that are covered in these five practice sessions that cover stages 1-5 of the C# Objects course.
- Practice Creating Classes in C#
- Practice Methods in C#
- Practice Inheritance in C#
- Practice Encapsulation and Arrays in C#
- Practice Properties in C#
If you haven't completed these practice sessions yet, you might consider doing that first before attempting this practice session.
Add a method named
DisplayItems()to the MediaLibrary class.
- Use a
forloop to loop through the items array contained within the MediaLibrary class.
- Cast each item to its subtype and access its
DisplayTextproperty, passing the property's value to a
- Use a
In the Program.cs file, replace the calls to the
Display()method with a single call to the
If you get stuck on any of the following topics or simply need a refresher, click on a topic in list below to view the associated video in the C# Objects course.
You need to sign up for Treehouse in order to download course files.Sign up