Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Encapsulation and Arrays in C#!
You have completed Practice Encapsulation and Arrays in C#!
In this video, we'll see how to explicitly cast a base type to a subtype and we'll introduce our second challenge—creating a class in order to encapsulate our media type items array.
Instructions
2nd Challenge
-
Encapsulate the array of media type items inside of a class.
- Create a class named "MediaLibrary".
-
In the MediaLibrary class...
- Define a private array field of type MediaType named
_items
. - Initialize the array via a constructor method that accepts an array of media type items.
- Add a method named
GetItemAt()
that accepts an index value and returns the media type item at the provided index.
- Define a private array field of type MediaType named
-
In the Program.cs file
Main()
method...- Instantiate an instance of the MediaLibrary class.
- Pass into the constructor the existing collection of items.
- Update the rest of the code to use the
GetItemAt()
method to retrieve items from the media library.
Abstract Members
For more information about abstract classes and class members in C# see the Intermediate C# course in the Treehouse library.
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