FAQ: Arrays - Documentation Hunt

This community-built FAQ covers the “Documentation Hunt” exercise from the lesson “Arrays”.

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

Learn C#

FAQs on the exercise Documentation Hunt

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!

I used Array.Fill when it asked me to set every rating in the ratings array to 0, but it wouldn’t accept the solution and told me to use Array.Clear. Is this just the way it was coded, or is there a specific reason to use Array.Clear for this?

           Array.Clear(ratings, 0, ratings.Length);

Wouldn’t passing in the length of the array exceed the bounds here? Should it not be ratings.Length-1?

I’m asking only because the hint in the example states “To clear an entire array, set the index to 0 (if it is zero-indexed) and then pass in the length of the array for the third parameter.”.

If we refer to the documentation for the Array.Clear method, we can see that the second parameter of this method is “The starting index of the range of elements to clear.” BUT the third parameter is NOT the index of the last element. Had it been the index of the last element, then your observation would be correct and we would use ratings.Length - 1.

The third parameter of the Array.Clear method is “The number of elements to clear.” So the Array.Length property (ratings.Length in this particular case) is the correct code, as the property gives us the number of elements in the array.

I did Array.Clear(ratings,0,7);
Then I tried Console.WriteLine(ratings);
This was what was printed:

Not the array {0,0,0,0,0,0,0}. Why?

For things like integers, double, strings etc., the Console.WriteLine() method works fine in displaying a text representation. But for certain objects like Arrays, the textual representation displayed by the Console.WriteLine() method is basically a description of the type of the object.
If you do Console.WriteLine(ratings), you will see “System.Int32
If you do Console.WriteLine(summerStrut), you will see “System.String

If you want to see the elements of the array, you can try looping over the array.
One way to do so can be

foreach (int rating in ratings) {

Another way could be
Array.ForEach(ratings, Console.WriteLine);

1 Like