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 Inheritance in C#!
You have completed Practice Inheritance in C#!
In this video, we'll review the solution to the second challenge and introduce our third challenge—adding a helper method that'll identify a media type item's specific subtype.
Instructions
3rd Challenge
-
In the Program.cs file, create a static method named
DetectMediaType()
.- Define a parameter named
item
that's of typeMediaType
.
- Define a parameter named
-
In the
DetectMediaType()
method body, use a series of conditional statements and the C#is
operator to identity which particular media type subclass (i.e. Album, Book, Movie, etc.) theitem
parameter is an instance of.- Once the media type item's subclass type has been determined, output a message to the console that identifies that type.
- For example, if the
item
parameter is of type "Album" and itsTitle
field is set to the value "Yellow Submarine", write the message "Yellow Submarine is an album!" to the console.
To test your changes, pass each media type subclass instance into a call to the
DetectMediaType()
method.
C# is
Operator
For more information about the C# is
operator see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/is.
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