FAQ: Reference Fundamentals - Arrays of References

This community-built FAQ covers the “Arrays of References” exercise from the lesson “Reference Fundamentals”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Arrays of References

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

The exercise doesn’t follow what the explanation says, while completely defeating the purpose of what has been explained in this lesson.
The starting code is this:

static void Main(string[] args)
Dissertation diss1 = new Dissertation(32, "Anna Knowles-Smith", "Refugees and Theatre");
Dissertation diss2 = new Dissertation(19, "Lajos Kossuth", "Shiny Happy People");
Diary dy1 = new Diary(48, "Anne Frank", "The Diary of a Young Girl");
Diary dy2 = new Diary(23, "Lili Elbe", "Man into Woman");

and the instructions tell me to create an array that contains diss1, diss2, dy1 and dy2.
This is what it accepts:
Book[] books = new Book[] {diss1, diss2, dy1, dy2}

Wouldn’t it be faster and better to just do this?

Book[] books = new Book[] 
new Dissertation(32, "Anna Knowles-Smith", "Refugees and Theatre"),
new Dissertation(19, "Lajos Kossuth", "Shiny Happy People"),
new Diary(48, "Anne Frank", "The Diary of a Young Girl"),
new Diary(23, "Lili Elbe", "Man into Woman")

and then the foreach loop still returns the same result.

1 Like

Instead of using an interface as suggested in the explanation to create an array, could an abstract class be used?

1 Like

i too think the same …

1 Like

What does your foreach loop look like?

I can’t get mine to print to the console.
This is mine:

foreach ( Book Title in books)

I figured it out. lol