Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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.
Prerequisites
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.
Instructions
1st Challenge
-
Add a method named
DisplayItems()
to the MediaLibrary class.- Use a
for
loop to loop through the items array contained within the MediaLibrary class. - Cast each item to its subtype and access its
DisplayText
property, passing the property's value to aConsole.WriteLine()
method call.
- Use a
In the Program.cs file, replace the calls to the
Display()
method with a single call to theDisplayItems()
method.
Help
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.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up