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


I did everything correctly but the console throws error CS1922, maybe because there is only program.cs available to us and other class cs files are hidden, this is dogshit really. Whole time it’s bugging me. Give me everything there is smh.

So not only do you INCORRECTLY create an array in the article but you also make me do the error and tell me it was correct even if it isn’t! Ridiculous, this course has been done by dogs!
IFlippable[ ] classroom = new IFlippable{};
I’ve been stuck for an hour or two wondering what the ■■■■ is wrong, I am sick of this.

It’d be better to change the variable name from Title to book.
Because we’re looping through classes, Title works but it might be confusing to others when they read your codes.

Or another example

int[] numbers = new int[] { 1, 2, 3, 4, 5 };
foreach (int number in numbers)
    // 1, 2, 3, 4, 5

I agree @kekpop, I was like “Whaaaaaaat???!!!” When I saw this, how could the devs forget the square brackets before the curly braces???

1 Like

@8-bit-gaming, feel like writing this one up? The instructions show as an example:


Needs to be either of the following:

Probably the first would be more consistent with the exercise, but the way it’s currently written throws the following error when learners try to follow the example code pattern.

1 Like

Sure thing!!
I just wrote out a report!

Thanks for posting this @kekpop.
It was most likely just a typo, and will soon be fixed.

@kekpop and @hypercoder457, hopefully you will be happy to know that this has been fixed!

Thanks again for the feedback. :slightly_smiling_face:

Thanks @8-bit-gaming

1 Like

If you want to access the other files to check the code there, you can always open the folder on top left corner where you enter your code and click on the file you want, it will open a new tab with the code inside. All codes are accessibles that way in every lesson.

It wouldn’t, on the contrary. What you’ve done is added 4 unnamed references to an array. References should be stored in a variable whenever possible since you are probably gonna use them more than once and do with them more than just write something out in terminal.
In Codecademy example you can access info under dy1 and diss1 knowing what you are accessing and it will make your life a lot easier when debugging, which you will be doing most of the time in app building :sweat_smile:

Any reason that I’m missing as to why the first book title prints twice and the second one does not print at all when running the code:

Book books = new Book { diss1, diss1, dy1, dy2 };
foreach(Book book in books)

But all steps show as completed correctly.

because you wrote twice diss1 instead of diss1, diss2