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 review the solution to the second challenge and introduce our third and final challenge—updating our MediaLibrary `GetItemAt()` method to gracefully handle bad array indexes.
Instructions
3rd Challenge
-
In the MediaLibrary class, update the
GetItemAt()
method to gracefully handle a bad index.- Use the array's
Length
property to determine if an index is available before attempting to access it. - Return
null
if the provided index isn't available in the array of items.
- Use the array's
In the Program.cs file, update the
Display()
andDetectMediaType()
methods to handle a nullitem
parameter value.
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